9f9eae
From 7620b422e515249bbfff02d0372301334fe1dd50 Mon Sep 17 00:00:00 2001
9f9eae
Message-Id: <7620b422e515249bbfff02d0372301334fe1dd50.1407860168.git.crobinso@redhat.com>
9f9eae
In-Reply-To: <2151695a5119a8d7f44d416c730df50a1e42695a.1407860168.git.crobinso@redhat.com>
9f9eae
References: <2151695a5119a8d7f44d416c730df50a1e42695a.1407860168.git.crobinso@redhat.com>
9f9eae
From: Eric Blake <eblake@redhat.com>
9f9eae
Date: Wed, 6 Aug 2014 14:48:59 -0600
9f9eae
Subject: [PATCH 2/3] blockjob: avoid memory leak during block pivot
9f9eae
9f9eae
Valgrind caught a memory leak:
9f9eae
9f9eae
==2018== 9 bytes in 1 blocks are definitely lost in loss record 143 of 927
9f9eae
==2018==    at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
9f9eae
==2018==    by 0x8C42369: strdup (strdup.c:42)
9f9eae
==2018==    by 0x50EACC9: virStrdup (virstring.c:676)
9f9eae
==2018==    by 0x50E79E5: virStorageSourceCopy (virstoragefile.c:1845)
9f9eae
==2018==    by 0x20A3FAA7: qemuDomainBlockCommit (qemu_driver.c:15620)
9f9eae
==2018==    by 0x51DC6B2: virDomainBlockCommit (libvirt.c:20092)
9f9eae
9f9eae
I traced it to the fact that blockcopy and blockcommit end up
9f9eae
reparsing a backing chain on pivot, but the chain parsing code
9f9eae
doesn't gracefully handle the case where the backing file is
9f9eae
already known.
9f9eae
9f9eae
I'm not exactly sure when this was introduced, but suspect that the
9f9eae
refactoring in commit 9944b71 and friends that moved towards probing
9f9eae
in-place rather than into a temporary structure are part of the cause.
9f9eae
9f9eae
* src/util/virstoragefile.c (virStorageFileGetMetadataInternal):
9f9eae
Don't leak any prior value.
9f9eae
9f9eae
Signed-off-by: Eric Blake <eblake@redhat.com>
9f9eae
(cherry picked from commit a595a005725f142e1a258d10f7647982efa3cfd8)
9f9eae
---
9f9eae
 src/util/virstoragefile.c | 1 +
9f9eae
 1 file changed, 1 insertion(+)
9f9eae
9f9eae
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
9f9eae
index 3da9073..5b6b2f5 100644
9f9eae
--- a/src/util/virstoragefile.c
9f9eae
+++ b/src/util/virstoragefile.c
9f9eae
@@ -817,6 +817,7 @@ virStorageFileGetMetadataInternal(virStorageSourcePtr meta,
9f9eae
             goto cleanup;
9f9eae
     }
9f9eae
 
9f9eae
+    VIR_FREE(meta->backingStoreRaw);
9f9eae
     if (fileTypeInfo[meta->format].getBackingStore != NULL) {
9f9eae
         int store = fileTypeInfo[meta->format].getBackingStore(&meta->backingStoreRaw,
9f9eae
                                                          backingFormat,
9f9eae
-- 
9f9eae
1.9.3
9f9eae