]> xenbits.xensource.com Git - 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)
committerMartin Kletzander <mkletzan@redhat.com>
Fri, 7 Apr 2017 06:49:34 +0000 (08:49 +0200)
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>
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 */