]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: json: fix memory leak in virJSONValueFromJsonC()
authorElizaveta Tereshkina <teryoshkina.ea@gmail.com>
Fri, 6 Mar 2026 10:46:20 +0000 (13:46 +0300)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 6 Mar 2026 12:24:18 +0000 (13:24 +0100)
In the 'json_type_object' and/ro 'json_type_array' cases, 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: 9e6555fd90988948a05e83466b1903bb95b36f39
Fixes: da66bf53b09ee8f5facacae700638a9a6f3a2477
Signed-off-by: Elizaveta Tereshkina <teryoshkina.ea@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virjson.c

index 454bd657beb69c33947cb17d7473128d1309b1fa..b7513261545fb5a3dd06c601d1c877e6af512ac4 100644 (file)
@@ -1416,7 +1416,7 @@ virJSONValueFromJsonC(json_object *jobj)
             virJSONValue *cur = virJSONValueFromJsonC(iter.val);
 
             if (virJSONValueObjectAppend(ret, iter.key, &cur) < 0) {
-                g_free(ret);
+                virJSONValueFree(ret);
                 return NULL;
             }
         }
@@ -1438,7 +1438,7 @@ virJSONValueFromJsonC(json_object *jobj)
             cur = virJSONValueFromJsonC(val);
 
             if (!cur) {
-                g_free(ret);
+                virJSONValueFree(ret);
                 return NULL;
             }