[PATCH 2/3] remote: Resolve resource leak

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

 



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@xxxxxxxxxx>
---
 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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux