]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Avoid memory leak in virQEMUCapsCPUDefsToModels
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 10 Oct 2022 13:37:17 +0000 (15:37 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 10 Oct 2022 13:47:54 +0000 (15:47 +0200)
The @vendor variable inside virQEMUCapsCPUDefsToModels() is
allocated, but never freed. But there is actually no need for it
to be allocated, because it merely passes a retval of
virCPUGetVendorForModel() (which returns a const string) to
virDomainCapsCPUModelsAdd() (which ten accepts the argument as
const string). Therefore, drop the g_strdup() call and fix the
type of the variable.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
src/qemu/qemu_capabilities.c

index 6f3ff7f43f67f5bda85cbc15138ba139e6cc626b..04b2eef2151c770f8993d18af2374aba90ac2bf3 100644 (file)
@@ -2189,7 +2189,7 @@ virQEMUCapsCPUDefsToModels(virArch arch,
 
     for (i = 0; i < defs->ncpus; i++) {
         qemuMonitorCPUDefInfo *cpu = defs->cpus + i;
-        char *vendor = NULL;
+        const char *vendor = NULL;
 
         if (modelAllowed && !g_strv_contains(modelAllowed, cpu->name))
             continue;
@@ -2198,7 +2198,7 @@ virQEMUCapsCPUDefsToModels(virArch arch,
             continue;
 
         if (vendors)
-            vendor = g_strdup(virCPUGetVendorForModel(arch, cpu->name));
+            vendor = virCPUGetVendorForModel(arch, cpu->name);
 
         virDomainCapsCPUModelsAdd(cpuModels, cpu->name, cpu->usable,
                                   cpu->blockers, cpu->deprecated, vendor);