[PATCHv2 1/2] vbox: snapshot: Avoid memleak in virVBoxSnapshotConfAllChildren

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

 



On re-allocation failure the function would leak already allocated
memory.
---
 src/vbox/vbox_snapshot_conf.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c
index 30ac6fe..ced0952 100644
--- a/src/vbox/vbox_snapshot_conf.c
+++ b/src/vbox/vbox_snapshot_conf.c
@@ -477,24 +477,32 @@ virVBoxSnapshotConfAllChildren(virVBoxSnapshotConfHardDiskPtr disk,
     virVBoxSnapshotConfHardDiskPtr *tempList = NULL;
     size_t i = 0;
     size_t j = 0;
+
     if (VIR_ALLOC_N(ret, 0) < 0)
         return 0;

     for (i = 0; i < disk->nchildren; i++) {
         tempSize = virVBoxSnapshotConfAllChildren(disk->children[i], &tempList);
         if (VIR_EXPAND_N(ret, returnSize, tempSize) < 0)
-            return 0;
+            goto error;

-        for (j = 0; j < tempSize; j++) {
+        for (j = 0; j < tempSize; j++)
             ret[returnSize - tempSize + j] = tempList[j];
-        }
+
+        VIR_FREE(tempList);
     }
+
     if (VIR_EXPAND_N(ret, returnSize, 1) < 0)
-        return 0;
+        goto error;

     ret[returnSize - 1] = disk;
     *list = ret;
     return returnSize;
+
+ error:
+    VIR_FREE(tempList);
+    VIR_FREE(ret);
+    return 0;
 }

 void
-- 
1.9.3

--
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]