[libvirt] PATCH: Fix memory leak in OOM cleanup for capabilities

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

 



The combo of the OOM testing and valgrind identified a place where we fail
to correctly free memory when cleaning up from an OOM failure in the NUMA
code for capabilities. This patch addresses that problem

Daniel

diff -r 0f3ebb9e7958 src/capabilities.c
--- a/src/capabilities.c	Thu Jul 03 11:42:29 2008 +0100
+++ b/src/capabilities.c	Thu Jul 03 14:24:20 2008 +0100
@@ -224,17 +224,19 @@
 
     if (VIR_ALLOC(cell) < 0)
         return -1;
-    caps->host.numaCell[caps->host.nnumaCell] = cell;
 
-    if (VIR_ALLOC_N(caps->host.numaCell[caps->host.nnumaCell]->cpus,
-                    ncpus) < 0)
+    if (VIR_ALLOC_N(cell->cpus, ncpus) < 0) {
+        VIR_FREE(cell);
         return -1;
-    memcpy(caps->host.numaCell[caps->host.nnumaCell]->cpus,
+    }
+    memcpy(cell->cpus,
            cpus,
            ncpus * sizeof(*cpus));
 
-    caps->host.numaCell[caps->host.nnumaCell]->ncpus = ncpus;
-    caps->host.numaCell[caps->host.nnumaCell]->num = num;
+    cell->ncpus = ncpus;
+    cell->num = num;
+
+    caps->host.numaCell[caps->host.nnumaCell] = cell;
     caps->host.nnumaCell++;
 
     return 0;

-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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