[PATCH] qemu_capabilities: Avoid memleak in virQEMUCapsProbeFullDeprecatedProperties()

Michal Privoznik posted 1 patch 3 days ago
src/qemu/qemu_capabilities.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] qemu_capabilities: Avoid memleak in virQEMUCapsProbeFullDeprecatedProperties()
Posted by Michal Privoznik 3 days ago
As one of its arguments, the
virQEMUCapsProbeFullDeprecatedProperties() gets a pointer to
GStrv (a string list), which it may eventually replace. It's
single caller (virQEMUCapsProbeQMPHostCPU()) passes a string list
indeed. Now, when replacing one string list with another plain
g_free() is not enough as we need to free individual strings too.

==13573== 34 bytes in 8 blocks are definitely lost in loss record 271 of 576
==13573==    at 0x4844878: malloc (vg_replace_malloc.c:446)
==13573==    by 0x51789D1: g_malloc (in /usr/lib64/libglib-2.0.so.0.7800.6)
==13573==    by 0x5193E82: g_strdup (in /usr/lib64/libglib-2.0.so.0.7800.6)
==13573==    by 0x4997F73: g_strdup_inline (gstrfuncs.h:321)
==13573==    by 0x4997F73: virJSONValueArrayToStringList (virjson.c:1296)
==13573==    by 0x5027CF7: qemuMonitorJSONParseCPUModelExpansion (qemu_monitor_json.c:5139)
==13573==    by 0x50281C9: qemuMonitorJSONGetCPUModelExpansion (qemu_monitor_json.c:5245)
==13573==    by 0x501044F: qemuMonitorGetCPUModelExpansion (qemu_monitor.c:3261)
==13573==    by 0x4F190D0: virQEMUCapsProbeQMPHostCPU (qemu_capabilities.c:3227)
==13573==    by 0x4F2145E: virQEMUCapsInitQMPMonitor (qemu_capabilities.c:5758)
==13573==    by 0x10FFF8: testQemuCaps (qemucapabilitiestest.c:111)
==13573==    by 0x110B53: virTestRun (testutils.c:143)
==13573==    by 0x11063E: doCapsTest (qemucapabilitiestest.c:200)

Fixes: 51c098347d7f2af9b4386ac0adc4431997d06f3d
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_capabilities.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index eda3e6a4df..27a283cff6 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3176,7 +3176,7 @@ virQEMUCapsProbeFullDeprecatedProperties(qemuMonitor *mon,
         return -1;
 
     if (propsInfo && propsInfo->deprecated_props) {
-        g_free(*props);
+        g_strfreev(*props);
         *props = g_steal_pointer(&propsInfo->deprecated_props);
     }
 
-- 
2.45.2
Re: [PATCH] qemu_capabilities: Avoid memleak in virQEMUCapsProbeFullDeprecatedProperties()
Posted by Boris Fiuczynski 3 days ago
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>

On 12/18/24 16:31, Michal Privoznik wrote:
> As one of its arguments, the
> virQEMUCapsProbeFullDeprecatedProperties() gets a pointer to
> GStrv (a string list), which it may eventually replace. It's
> single caller (virQEMUCapsProbeQMPHostCPU()) passes a string list
> indeed. Now, when replacing one string list with another plain
> g_free() is not enough as we need to free individual strings too.
> 
> ==13573== 34 bytes in 8 blocks are definitely lost in loss record 271 of 576
> ==13573==    at 0x4844878: malloc (vg_replace_malloc.c:446)
> ==13573==    by 0x51789D1: g_malloc (in /usr/lib64/libglib-2.0.so.0.7800.6)
> ==13573==    by 0x5193E82: g_strdup (in /usr/lib64/libglib-2.0.so.0.7800.6)
> ==13573==    by 0x4997F73: g_strdup_inline (gstrfuncs.h:321)
> ==13573==    by 0x4997F73: virJSONValueArrayToStringList (virjson.c:1296)
> ==13573==    by 0x5027CF7: qemuMonitorJSONParseCPUModelExpansion (qemu_monitor_json.c:5139)
> ==13573==    by 0x50281C9: qemuMonitorJSONGetCPUModelExpansion (qemu_monitor_json.c:5245)
> ==13573==    by 0x501044F: qemuMonitorGetCPUModelExpansion (qemu_monitor.c:3261)
> ==13573==    by 0x4F190D0: virQEMUCapsProbeQMPHostCPU (qemu_capabilities.c:3227)
> ==13573==    by 0x4F2145E: virQEMUCapsInitQMPMonitor (qemu_capabilities.c:5758)
> ==13573==    by 0x10FFF8: testQemuCaps (qemucapabilitiestest.c:111)
> ==13573==    by 0x110B53: virTestRun (testutils.c:143)
> ==13573==    by 0x11063E: doCapsTest (qemucapabilitiestest.c:200)
> 
> Fixes: 51c098347d7f2af9b4386ac0adc4431997d06f3d
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>   src/qemu/qemu_capabilities.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
> index eda3e6a4df..27a283cff6 100644
> --- a/src/qemu/qemu_capabilities.c
> +++ b/src/qemu/qemu_capabilities.c
> @@ -3176,7 +3176,7 @@ virQEMUCapsProbeFullDeprecatedProperties(qemuMonitor *mon,
>           return -1;
>   
>       if (propsInfo && propsInfo->deprecated_props) {
> -        g_free(*props);
> +        g_strfreev(*props);
>           *props = g_steal_pointer(&propsInfo->deprecated_props);
>       }
>   


-- 
Mit freundlichen Grüßen/Kind regards
    Boris Fiuczynski

IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Wolfgang Wendt
Geschäftsführung: David Faller
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294