[PATCH 3/3] virISCSIGetSession: Don't leak memory

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

 



This function runs an iscsi command and parses its output.
However, due to the nature of things, virISCSIExtractSession()
callback can be called multiple times. In each run it would
allocate new memory and overwrite the variable where we keep
pointer to it and thus leaking old allocations.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/util/viriscsi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c
index 504ffbd..9c6fde0 100644
--- a/src/util/viriscsi.c
+++ b/src/util/viriscsi.c
@@ -52,7 +52,8 @@ virISCSIExtractSession(char **const groups,
 {
     struct virISCSISessionData *data = opaque;
 
-    if (STREQ(groups[1], data->devpath))
+    if (!data->devpath &&
+        STREQ(groups[1], data->devpath))
         return VIR_STRDUP(data->session, groups[0]);
     return 0;
 }
-- 
2.10.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