]> xenbits.xensource.com Git - libvirt.git/commitdiff
virISCSIGetSession: Don't leak memory
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 5 Apr 2017 08:48:10 +0000 (10:48 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 5 Apr 2017 13:18:30 +0000 (15:18 +0200)
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@redhat.com>
src/util/viriscsi.c

index 504ffbd14bfa0e01628737dd3225c9ab4b881dab..d4c745a1afac265c50eaacc6ee6f7e0cf3590b22 100644 (file)
@@ -52,7 +52,8 @@ virISCSIExtractSession(char **const groups,
 {
     struct virISCSISessionData *data = opaque;
 
-    if (STREQ(groups[1], data->devpath))
+    if (!data->session &&
+        STREQ(groups[1], data->devpath))
         return VIR_STRDUP(data->session, groups[0]);
     return 0;
 }