Skip to contentSkip to conversation

block/qcow.c: Fix memory leak in qcow_create()

PATCH Applied Peter Maydell 4 participants 4 messages Jun 5, 2017 – Jun 6, 2017 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block/qcow.c: Fix memory leak in qcow_create()

Coverity points out that the code path in qcow_create() for the magic "fat:" backing file name leaks the memory used to store the filename (CID 1307771). Free the memory before we overwrite the pointer.

---
 block/qcow.c | 1 +
 1 file changed, 1 insertion(+)
block/qcow.c +1 -0
index 95ab123..7bd94dc 100644
@@ -852,6 +852,7 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)
             header_size += backing_filename_len;
         } else {
             /* special backing file for vvfat */
+            g_free(backing_file);
             backing_file = NULL;
         }
         header.cluster_bits = 9; /* 512 byte cluster to avoid copying
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Peter Maydell

Coverity points out that the code path in qcow_create() for the magic "fat:" backing file name leaks the memory used to store the filename (CID 1307771). Free the memory before we overwrite the pointer.

---
 block/qcow.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 14 lines
block/qcow.c +1 -0
index 95ab123..7bd94dc 100644
@@ -852,6 +852,7 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)
             header_size += backing_filename_len;
         } else {
             /* special backing file for vvfat */
+            g_free(backing_file);
             backing_file = NULL;
         }
         header.cluster_bits = 9; /* 512 byte cluster to avoid copying
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
Reviewed-by on v1 1/1
#2 lore raw
In reply to Peter Maydell
Quoted 6 lines · Peter Maydell

Coverity points out that the code path in qcow_create() for the magic "fat:" backing file name leaks the memory used to store the filename (CID 1307771). Free the memory before we overwrite the pointer.

Quoted 17 lines
---
 block/qcow.c | 1 +
 1 file changed, 1 insertion(+)
block/qcow.c +1 -0
index 95ab123..7bd94dc 100644
@@ -852,6 +852,7 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)
             header_size += backing_filename_len;
         } else {
             /* special backing file for vvfat */
+            g_free(backing_file);
             backing_file = NULL;
         }
         header.cluster_bits = 9; /* 512 byte cluster to avoid copying
Applied
#3 lore raw
In reply to Peter Maydell

Am 05.06.2017 um 15:55 hat Peter Maydell geschrieben:

Quoted 6 lines

Coverity points out that the code path in qcow_create() for the magic "fat:" backing file name leaks the memory used to store the filename (CID 1307771). Free the memory before we overwrite the pointer.

Thanks, applied to the block branch.

Kevin