]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix memory leak in virNWFilterDefParseXML()
authorNehal J Wani <nehaljw.kkd1@gmail.com>
Fri, 29 Nov 2013 15:28:51 +0000 (20:58 +0530)
committerDaniel Veillard <veillard@redhat.com>
Mon, 2 Dec 2013 02:39:44 +0000 (10:39 +0800)
While running nwfilterxml2xmltest, it was found that valgrind pointed out the
following error...

==7466== 16 bytes in 1 blocks are definitely lost in loss record 26 of 90
==7466==    at 0x4A06B6F: calloc (vg_replace_malloc.c:593)
    ==7466==    by 0x4C651AD: virAlloc (viralloc.c:142)
    ==7466==    by 0x4D0450D: virNWFilterDefParseNode (nwfilter_conf.c:2575)
    ==7466==    by 0x4D05D84: virNWFilterDefParse (nwfilter_conf.c:2647)
    ==7466==    by 0x401FDE: testCompareXMLToXMLHelper (nwfilterxml2xmltest.c:39)
    ==7466==    by 0x402DE1: virtTestRun (testutils.c:138)
    ==7466==    by 0x4018E9: mymain (nwfilterxml2xmltest.c:111)
    ==7466==    by 0x403482: virtTestMain (testutils.c:593)
    ==7466==    by 0x341F421A04: (below main) (libc-start.c:225)

...21 times, which are related to 21 tests in nwfilterxml2xmltest.c which sent
EXPECT_WARN = false. There were two scenarios in virNWFilterDefParseXML(),
when the variable 'entry' was malloc'ed, but not freed.

src/conf/nwfilter_conf.c

index 793cb0e9cd27b92a71a6f172f8aa2b7d7ef8082b..d280df5e04c5b92a74d2d9a6197ff91e76b1e9b7 100644 (file)
@@ -2576,21 +2576,25 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt) {
                 goto cleanup;
 
             if (xmlStrEqual(curr->name, BAD_CAST "rule")) {
-                if (!(entry->rule = virNWFilterRuleParse(curr)))
+                if (!(entry->rule = virNWFilterRuleParse(curr))) {
+                    virNWFilterEntryFree(entry);
                     goto cleanup;
+                }
             } else if (xmlStrEqual(curr->name, BAD_CAST "filterref")) {
-                if (!(entry->include = virNWFilterIncludeParse(curr)))
+                if (!(entry->include = virNWFilterIncludeParse(curr))) {
+                    virNWFilterEntryFree(entry);
                     goto cleanup;
+                }
             }
 
             if (entry->rule || entry->include) {
                 if (VIR_REALLOC_N(ret->filterEntries, ret->nentries+1) < 0) {
-                    VIR_FREE(entry);
+                    virNWFilterEntryFree(entry);
                     goto cleanup;
                 }
                 ret->filterEntries[ret->nentries++] = entry;
             } else
-                VIR_FREE(entry);
+                virNWFilterEntryFree(entry);
         }
         curr = curr->next;
     }