[PATCH] util: json: fix memory leak in virJSONValueFromJsonC()

Elizaveta Tereshkina posted 1 patch 2 weeks, 3 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20260306103659.90975-1-teryoshkina.ea@gmail.com
There is a newer version of this series
src/util/virjson.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] util: json: fix memory leak in virJSONValueFromJsonC()
Posted by Elizaveta Tereshkina 2 weeks, 3 days ago
In the 'json_type_array' case, the error path uses 'g_free()',
which doesn't release other nested memory allocations.
Replace it with 'virJSONValueFree()' to properly free
the entire 'virJSONValue' structure.

Fixes: da66bf53b0 (util: json: check return value of virJSONValueFromJsonC)
Signed-off-by: Elizaveta Tereshkina <teryoshkina.ea@gmail.com>
---
 src/util/virjson.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/util/virjson.c b/src/util/virjson.c
index 454bd657be..5780dbb094 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -1438,7 +1438,7 @@ virJSONValueFromJsonC(json_object *jobj)
             cur = virJSONValueFromJsonC(val);
 
             if (!cur) {
-                g_free(ret);
+                virJSONValue(ret);
                 return NULL;
             }
 
-- 
2.39.2
Re: [PATCH] util: json: fix memory leak in virJSONValueFromJsonC()
Posted by Elizaveta Tereshkina 2 weeks, 3 days ago
I've attached the wrong patch, I've created a new email