]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu_capabilities: Resolve Coverity RESOURCE_LEAK
authorJohn Ferlan <jferlan@redhat.com>
Wed, 27 Aug 2014 18:57:08 +0000 (14:57 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 28 Aug 2014 12:12:16 +0000 (08:12 -0400)
Coverity determined that on error path that 'mach' wouldn't be free'd
Since virCapabilitiesFreeGuestMachine() isn't globally available, we'll
insert first and then if the VIR_STRDUP's fail they it will eventually
cause the 'mach' to be freed in the error path

src/qemu/qemu_capabilities.c

index 4a540eec9e73d6f77aacb6da1b0962bb800db3e3..e8614151d88ff2fd445942fa0a4645c48bde01aa 100644 (file)
@@ -2108,6 +2108,7 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
         virCapsGuestMachinePtr mach;
         if (VIR_ALLOC(mach) < 0)
             goto error;
+        (*machines)[i] = mach;
         if (qemuCaps->machineAliases[i]) {
             if (VIR_STRDUP(mach->name, qemuCaps->machineAliases[i]) < 0 ||
                 VIR_STRDUP(mach->canonical, qemuCaps->machineTypes[i]) < 0)
@@ -2117,7 +2118,6 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
                 goto error;
         }
         mach->maxCpus = qemuCaps->machineMaxCpus[i];
-        (*machines)[i] = mach;
     }
 
     return 0;