]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
networkxml2conftest: Avoid potential leak
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 17 Dec 2025 12:17:02 +0000 (13:17 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 29 Jan 2026 12:38:49 +0000 (13:38 +0100)
Inside of testCompareXMLToConfFiles() the network definition is
parsed and if that succeeds a virNetworkObj is created by calling
virNetworkObjNew(). But if the latter fails, the control jumps
onto the fail label where only the object is freed but not
already parsed definition leading to a leak.

Swapping these two steps ensures that if either of them fails no
memleak occurs.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/networkxml2conftest.c

index 67856f2e8caaa5d9c96d0a9d6e10088a3fe087df..d089ff38b17909ddb88aa407caf27605fe51e2d0 100644 (file)
@@ -33,17 +33,17 @@ testCompareXMLToConfFiles(const char *inxml, const char *outconf,
     if (!(xmlopt = networkDnsmasqCreateXMLConf()))
         goto fail;
 
-    if (!(def = virNetworkDefParse(NULL, inxml, xmlopt, false)))
-        goto fail;
-
-    if (networkValidateTests(def) < 0)
+    if (!(obj = virNetworkObjNew()))
         goto fail;
 
-    if (!(obj = virNetworkObjNew()))
+    if (!(def = virNetworkDefParse(NULL, inxml, xmlopt, false)))
         goto fail;
 
     virNetworkObjSetDef(obj, def);
 
+    if (networkValidateTests(def) < 0)
+        goto fail;
+
     if (!networkNeedsDnsmasq(def)) {
         VIR_TEST_VERBOSE("spurious request to generate conf files. Would not start dnsmasq in real life scenario");
         goto fail;