Just like we have VIR_FREE() which sets pointer to NULL,
we should have virCommandFree() to act the same.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/fdstream.c | 1 -
src/libvirt_private.syms | 2 +-
src/qemu/qemu_driver.c | 1 -
src/storage/storage_backend_logical.c | 3 ---
src/util/vircommand.c | 11 ++++++++---
src/util/vircommand.h | 4 +++-
src/util/virnetdevveth.c | 1 -
7 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/src/fdstream.c b/src/fdstream.c
index f7dae39..4acb821 100644
--- a/src/fdstream.c
+++ b/src/fdstream.c
@@ -321,7 +321,6 @@ virFDStreamCloseInt(virStreamPtr st, bool streamAbort)
ret = -1;
}
virCommandFree(fdst->cmd);
- fdst->cmd = NULL;
}
if (VIR_CLOSE(fdst->errfd) < 0)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 25beda2..1ecef26 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1065,7 +1065,7 @@ virCommandClearCaps;
virCommandDaemonize;
virCommandDoAsyncIO;
virCommandExec;
-virCommandFree;
+virCommandFreeInternal;
virCommandHandshakeNotify;
virCommandHandshakeWait;
virCommandNew;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9c3daad..688c535 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11605,7 +11605,6 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver,
goto cleanup;
virCommandFree(cmd);
- cmd = NULL;
}
/* update disk definitions */
diff --git a/src/storage/storage_backend_logical.c
b/src/storage/storage_backend_logical.c
index 10966cc..ddeec29 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -644,7 +644,6 @@ virStorageBackendLogicalDeletePool(virConnectPtr conn
ATTRIBUTE_UNUSED,
if (virCommandRun(cmd, NULL) < 0)
goto cleanup;
virCommandFree(cmd);
- cmd = NULL;
/* now remove the pv devices and clear them out */
ret = 0;
@@ -657,7 +656,6 @@ virStorageBackendLogicalDeletePool(virConnectPtr conn
ATTRIBUTE_UNUSED,
break;
}
virCommandFree(cmd);
- cmd = NULL;
}
cleanup:
@@ -720,7 +718,6 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
goto error;
virCommandFree(cmd);
- cmd = NULL;
if ((fd = virStorageBackendVolOpen(vol->target.path)) < 0)
goto error;
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 8dcf9e7..2f8c534 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -2561,7 +2561,7 @@ int virCommandHandshakeNotify(virCommandPtr cmd)
/**
- * virCommandFree:
+ * virCommandFreeInternal:
* @cmd: optional command to free
*
* Release all resources. The only exception is that if you called
@@ -2569,12 +2569,16 @@ int virCommandHandshakeNotify(virCommandPtr cmd)
* is not reaped, and you must call virProcessWait() or virProcessAbort() yourself.
*/
void
-virCommandFree(virCommandPtr cmd)
+virCommandFreeInternal(virCommandPtr *ptr)
{
+ virCommandPtr cmd;
size_t i;
- if (!cmd)
+
+ if (!ptr || !*ptr)
return;
+ cmd = *ptr;
+
for (i = 0; i < cmd->npassfd; i++) {
if (cmd->passfd[i].flags & VIR_COMMAND_PASS_FD_CLOSE_PARENT)
VIR_FORCE_CLOSE(cmd->passfd[i].fd);
@@ -2621,6 +2625,7 @@ virCommandFree(virCommandPtr cmd)
#endif
VIR_FREE(cmd);
+ *ptr = NULL;
}
/**
diff --git a/src/util/vircommand.h b/src/util/vircommand.h
index e977f93..ce7e9ab 100644
--- a/src/util/vircommand.h
+++ b/src/util/vircommand.h
@@ -181,7 +181,9 @@ int virCommandHandshakeNotify(virCommandPtr cmd)
void virCommandAbort(virCommandPtr cmd);
-void virCommandFree(virCommandPtr cmd);
+# define virCommandFree(ptr) \
+ virCommandFreeInternal(&(ptr))
+void virCommandFreeInternal(virCommandPtr *cmd);
void virCommandDoAsyncIO(virCommandPtr cmd);
#endif /* __VIR_COMMAND_H__ */
diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c
index 25eb282..737563f 100644
--- a/src/util/virnetdevveth.c
+++ b/src/util/virnetdevveth.c
@@ -171,7 +171,6 @@ int virNetDevVethCreate(char** veth1, char** veth2)
VIR_FREE(veth1auto);
VIR_FREE(veth2auto);
virCommandFree(cmd);
- cmd = NULL;
}
virReportError(VIR_ERR_INTERNAL_ERROR,
--
1.8.1.5