mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-20 11:35:19 +00:00
util: command: use g_new0
Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
3cb9a07424
commit
0275b06a55
@ -935,8 +935,7 @@ virCommandNewArgs(const char *const*args)
|
|||||||
{
|
{
|
||||||
virCommandPtr cmd;
|
virCommandPtr cmd;
|
||||||
|
|
||||||
if (VIR_ALLOC(cmd) < 0)
|
cmd = g_new0(virCommand, 1);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
cmd->handshakeWait[0] = -1;
|
cmd->handshakeWait[0] = -1;
|
||||||
cmd->handshakeWait[1] = -1;
|
cmd->handshakeWait[1] = -1;
|
||||||
@ -2183,21 +2182,18 @@ virCommandProcessIO(virCommandPtr cmd)
|
|||||||
if (cmd->outbuf) {
|
if (cmd->outbuf) {
|
||||||
outfd = cmd->outfd;
|
outfd = cmd->outfd;
|
||||||
VIR_FREE(*cmd->outbuf);
|
VIR_FREE(*cmd->outbuf);
|
||||||
if (VIR_ALLOC_N(*cmd->outbuf, 1) < 0)
|
*cmd->outbuf = g_new0(char, 1);
|
||||||
ret = -1;
|
|
||||||
}
|
}
|
||||||
if (cmd->errbuf) {
|
if (cmd->errbuf) {
|
||||||
errfd = cmd->errfd;
|
errfd = cmd->errfd;
|
||||||
VIR_FREE(*cmd->errbuf);
|
VIR_FREE(*cmd->errbuf);
|
||||||
if (VIR_ALLOC_N(*cmd->errbuf, 1) < 0)
|
*cmd->errbuf = g_new0(char, 1);
|
||||||
ret = -1;
|
|
||||||
}
|
}
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(fds, 3 + virCommandGetNumSendBuffers(cmd)) < 0)
|
fds = g_new0(struct pollfd, 3 + virCommandGetNumSendBuffers(cmd));
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -2636,8 +2632,7 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid)
|
|||||||
VIR_FORCE_CLOSE(cmd->infd);
|
VIR_FORCE_CLOSE(cmd->infd);
|
||||||
/* clear any error so we can catch if the helper thread reports one */
|
/* clear any error so we can catch if the helper thread reports one */
|
||||||
cmd->has_error = 0;
|
cmd->has_error = 0;
|
||||||
if (VIR_ALLOC(cmd->asyncioThread) < 0)
|
cmd->asyncioThread = g_new0(virThread, 1);
|
||||||
ret = -1;
|
|
||||||
|
|
||||||
if (virThreadCreateFull(cmd->asyncioThread, true,
|
if (virThreadCreateFull(cmd->asyncioThread, true,
|
||||||
virCommandDoAsyncIOHelper,
|
virCommandDoAsyncIOHelper,
|
||||||
@ -2854,10 +2849,7 @@ int virCommandHandshakeWait(virCommandPtr cmd)
|
|||||||
if (c != '1') {
|
if (c != '1') {
|
||||||
g_autofree char *msg = NULL;
|
g_autofree char *msg = NULL;
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
if (VIR_ALLOC_N(msg, 1024) < 0) {
|
msg = g_new0(char, 1024);
|
||||||
VIR_FORCE_CLOSE(cmd->handshakeWait[0]);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
/* Close the handshakeNotify fd before trying to read anything
|
/* Close the handshakeNotify fd before trying to read anything
|
||||||
* further on the handshakeWait pipe; so that a child waiting
|
* further on the handshakeWait pipe; so that a child waiting
|
||||||
* on our acknowledgment will die rather than deadlock. */
|
* on our acknowledgment will die rather than deadlock. */
|
||||||
@ -3193,8 +3185,7 @@ virCommandRunRegex(virCommandPtr cmd,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
/* Compile all regular expressions */
|
/* Compile all regular expressions */
|
||||||
if (VIR_ALLOC_N(reg, nregex) < 0)
|
reg = g_new0(GRegex *, nregex);
|
||||||
return -1;
|
|
||||||
|
|
||||||
for (i = 0; i < nregex; i++) {
|
for (i = 0; i < nregex; i++) {
|
||||||
g_autoptr(GError) err = NULL;
|
g_autoptr(GError) err = NULL;
|
||||||
@ -3212,8 +3203,7 @@ virCommandRunRegex(virCommandPtr cmd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Storage for matched variables */
|
/* Storage for matched variables */
|
||||||
if (VIR_ALLOC_N(groups, totgroups) < 0)
|
groups = g_new0(char *, totgroups);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
virCommandSetOutputBuffer(cmd, &outbuf);
|
virCommandSetOutputBuffer(cmd, &outbuf);
|
||||||
if (virCommandRun(cmd, exitstatus) < 0)
|
if (virCommandRun(cmd, exitstatus) < 0)
|
||||||
@ -3299,8 +3289,7 @@ virCommandRunNul(virCommandPtr cmd,
|
|||||||
if (n_columns == 0)
|
if (n_columns == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(v, n_columns) < 0)
|
v = g_new0(char *, n_columns);
|
||||||
return -1;
|
|
||||||
for (i = 0; i < n_columns; i++)
|
for (i = 0; i < n_columns; i++)
|
||||||
v[i] = NULL;
|
v[i] = NULL;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user