]> xenbits.xensource.com Git - libvirt.git/commitdiff
Fix memory leak in virDomainSnapshotDiskDefClear()
authorNehal J Wani <nehaljw.kkd1@gmail.com>
Sun, 16 Mar 2014 08:39:30 +0000 (14:09 +0530)
committerJán Tomko <jtomko@redhat.com>
Mon, 17 Mar 2014 17:38:58 +0000 (18:38 +0100)
While running domainsnapshotxml2xmltest, it was found that valgrind pointed out
the following memory leak:

==32176== 42 (32 direct, 10 indirect) bytes in 1 blocks are definitely lost in loss record 42 of 66
==32176==    at 0x4A069EE: malloc (vg_replace_malloc.c:270)
==32176==    by 0x4A06B62: realloc (vg_replace_malloc.c:662)
==32176==    by 0x4C65A07: virReallocN (viralloc.c:243)
==32176==    by 0x4C65B2E: virExpandN (viralloc.c:292)
==32176==    by 0x4C65E30: virInsertElementsN (viralloc.c:434)
==32176==    by 0x4CD71F3: virDomainDiskSourceDefParse (domain_conf.c:5078)
==32176==    by 0x4CF6EF4: virDomainSnapshotDefParseNode (snapshot_conf.c:151)
==32176==    by 0x4CF7314: virDomainSnapshotDefParseString (snapshot_conf.c:410)
==32176==    by 0x41FB8D: testCompareXMLToXMLHelper (domainsnapshotxml2xmltest.c:100)
==32176==    by 0x420FD1: virtTestRun (testutils.c:199)
==32176==    by 0x41F859: mymain (domainsnapshotxml2xmltest.c:222)
==32176==    by 0x42174D: virtTestMain (testutils.c:782)
==32176==
... and one more.

src/conf/snapshot_conf.c

index d70d1767abfca21def9c9c4dd015f12de212fa1b..546e5b3f5ddc5e718f0e105355412f8ceddcb76a 100644 (file)
@@ -82,6 +82,9 @@ virDomainSnapshotDiskDefClear(virDomainSnapshotDiskDefPtr disk)
 {
     VIR_FREE(disk->name);
     VIR_FREE(disk->file);
+    while (disk->nhosts)
+        virDomainDiskHostDefClear(&disk->hosts[--disk->nhosts]);
+    VIR_FREE(disk->hosts);
 }
 
 void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def)