[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 2/3] remote: Resolve resource leak



Using a combination of VIR_ALLOC and VIR_STRDUP into a local
variable and then jumping to error on the VIR_STRDUP before
assiging it into the @data would cause a memory leak. Let's
just avoid that by assiging directly into @data.

Signed-off-by: John Ferlan <jferlan redhat com>
---
 src/remote/remote_daemon_dispatch.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c
index 51bc055564..5cefc8480e 100644
--- a/src/remote/remote_daemon_dispatch.c
+++ b/src/remote/remote_daemon_dispatch.c
@@ -749,7 +749,6 @@ remoteRelayDomainEventDiskChange(virConnectPtr conn,
 {
     daemonClientEventCallbackPtr callback = opaque;
     remote_domain_event_disk_change_msg data;
-    char **oldSrcPath_p = NULL, **newSrcPath_p = NULL;
 
     if (callback->callbackID < 0 ||
         !remoteRelayDomainEventCheckACL(callback->client, conn, dom))
@@ -762,17 +761,15 @@ remoteRelayDomainEventDiskChange(virConnectPtr conn,
     /* build return data */
     memset(&data, 0, sizeof(data));
     if (oldSrcPath &&
-        ((VIR_ALLOC(oldSrcPath_p) < 0) ||
-         VIR_STRDUP(*oldSrcPath_p, oldSrcPath) < 0))
+        ((VIR_ALLOC(data.oldSrcPath) < 0) ||
+         VIR_STRDUP(*(data.oldSrcPath), oldSrcPath) < 0))
         goto error;
 
     if (newSrcPath &&
-        ((VIR_ALLOC(newSrcPath_p) < 0) ||
-         VIR_STRDUP(*newSrcPath_p, newSrcPath) < 0))
+        ((VIR_ALLOC(data.newSrcPath) < 0) ||
+         VIR_STRDUP(*(data.newSrcPath), newSrcPath) < 0))
         goto error;
 
-    data.oldSrcPath = oldSrcPath_p;
-    data.newSrcPath = newSrcPath_p;
     if (VIR_STRDUP(data.devAlias, devAlias) < 0)
         goto error;
     data.reason = reason;
@@ -1779,7 +1776,6 @@ remoteRelayDomainQemuMonitorEvent(virConnectPtr conn,
 {
     daemonClientEventCallbackPtr callback = opaque;
     qemu_domain_monitor_event_msg data;
-    char **details_p = NULL;
 
     if (callback->callbackID < 0 ||
         !remoteRelayDomainQemuMonitorEventCheckACL(callback->client, conn,
@@ -1797,10 +1793,9 @@ remoteRelayDomainQemuMonitorEvent(virConnectPtr conn,
     data.seconds = seconds;
     data.micros = micros;
     if (details &&
-        ((VIR_ALLOC(details_p) < 0) ||
-         VIR_STRDUP(*details_p, details) < 0))
+        ((VIR_ALLOC(data.details) < 0) ||
+         VIR_STRDUP(*(data.details), details) < 0))
         goto error;
-    data.details = details_p;
     if (make_nonnull_domain(&data.dom, dom) < 0)
         goto error;
 
-- 
2.17.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]