]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virStorageSourceClear: Don't leave dangling pointers behind
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 5 Apr 2017 07:59:25 +0000 (09:59 +0200)
committerCole Robinson <crobinso@redhat.com>
Wed, 10 May 2017 19:15:21 +0000 (15:15 -0400)
Imagine that this function is called twice over the same disk
source. While in the first run all allocated memory is freed, not
all pointers are set to NULL (e.g. def->srcpool). So when called
again, these poitners are freed again resulting in double free.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit 349badbffd50f86580884b29fdfa7ad6ea082c2e)

src/util/virstoragefile.c

index a51622affe5cff7a516bc5454b51a985da328589..94a77ce862da5d183f6fb819f501bad584976a0a 100644 (file)
@@ -2274,6 +2274,8 @@ virStorageSourceClear(virStorageSourcePtr def)
     VIR_FREE(def->nodeformat);
 
     virStorageSourceBackingStoreClear(def);
+
+    memset(def, 0, sizeof(*def));
 }