]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
network: eliminate potential memory leak on parse failure
authorLaine Stump <laine@laine.org>
Thu, 11 Aug 2011 03:28:05 +0000 (23:28 -0400)
committerLaine Stump <laine@laine.org>
Thu, 11 Aug 2011 18:39:22 +0000 (14:39 -0400)
While the first encountered dns host record is being parsed, it's
possible for virNetworkDef::hosts to point to memory that has been
allocated, but virNetworkDef::nhosts to still be 0. If there is a
failure during that time, virNetworkDef::hosts will be leaked.

Although this isn't currently the case for virNetworkDef::txtrecords,
it could become that way through future re-factoring, and it hurts
nothing to restructure the freeing of txtrecord data to match that of
hosts data.

src/conf/network_conf.c

index b11c4820aaff9613751c87af42f546e02a1cb31f..e055094c15ddee37d34f983b84e172e3f22ce810 100644 (file)
@@ -127,16 +127,16 @@ static void virNetworkDNSDefFree(virNetworkDNSDefPtr def)
                 VIR_FREE(def->txtrecords[def->ntxtrecords].name);
                 VIR_FREE(def->txtrecords[def->ntxtrecords].value);
             }
-            VIR_FREE(def->txtrecords);
         }
+        VIR_FREE(def->txtrecords);
         if (def->nhosts) {
             while (def->nhosts--) {
                 while (def->hosts[def->nhosts].nnames--)
                     VIR_FREE(def->hosts[def->nhosts].names[def->hosts[def->nhosts].nnames]);
                 VIR_FREE(def->hosts[def->nhosts].names);
             }
-            VIR_FREE(def->hosts);
         }
+        VIR_FREE(def->hosts);
         VIR_FREE(def);
     }
 }