]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Fix possible memleak in capabilities
authorMartin Kletzander <mkletzan@redhat.com>
Wed, 29 Mar 2017 11:36:15 +0000 (13:36 +0200)
committerCole Robinson <crobinso@redhat.com>
Wed, 10 May 2017 19:18:38 +0000 (15:18 -0400)
If formatting NUMA topology fails, the function returns immediatelly,
but the buffer structure allocated on the stack references lot of
heap-allocated memory and that would get lost in such case.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
(cherry picked from commit 6369ee0483b99ec4d2e624e9a32e35b7bdd9ab8a)

src/conf/capabilities.c

index 08907aced1b99e3d8379e78410c4dace5f6f8331..be95c50cfb67de4d073be5904b4f9def89c80cb8 100644 (file)
@@ -955,7 +955,7 @@ virCapabilitiesFormatXML(virCapsPtr caps)
     if (caps->host.nnumaCell &&
         virCapabilitiesFormatNUMATopology(&buf, caps->host.nnumaCell,
                                           caps->host.numaCell) < 0)
-        return NULL;
+        goto error;
 
     for (i = 0; i < caps->host.nsecModels; i++) {
         virBufferAddLit(&buf, "<secmodel>\n");
@@ -1072,6 +1072,10 @@ virCapabilitiesFormatXML(virCapsPtr caps)
         return NULL;
 
     return virBufferContentAndReset(&buf);
+
+ error:
+    virBufferFreeAndReset(&buf);
+    return NULL;
 }
 
 /* get the maximum ID of cpus in the host */