* [Qemu-devel] [PATCH] vvfat: Fix memory leak
@ 2018-11-14 12:55 Kevin Wolf
2018-11-14 13:28 ` Philippe Mathieu-Daudé
2018-11-14 14:50 ` Liam Merwick
0 siblings, 2 replies; 3+ messages in thread
From: Kevin Wolf @ 2018-11-14 12:55 UTC (permalink / raw)
To: qemu-block; +Cc: kwolf, mreitz, Liam.Merwick, qemu-devel
Don't leak 'cluster' in the mapping == NULL case. Found by Coverity
(CID 1055918).
Fixes: 8d9401c2791ee2d2805b741b1ee3006041edcd3e
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/vvfat.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/block/vvfat.c b/block/vvfat.c
index 1de5de1db4..b7b61ea8b7 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2510,7 +2510,7 @@ static int commit_one_file(BDRVVVFATState* s,
uint32_t first_cluster = c;
mapping_t* mapping = find_mapping_for_cluster(s, c);
uint32_t size = filesize_of_direntry(direntry);
- char* cluster = g_malloc(s->cluster_size);
+ char *cluster;
uint32_t i;
int fd = 0;
@@ -2528,17 +2528,17 @@ static int commit_one_file(BDRVVVFATState* s,
if (fd < 0) {
fprintf(stderr, "Could not open %s... (%s, %d)\n", mapping->path,
strerror(errno), errno);
- g_free(cluster);
return fd;
}
if (offset > 0) {
if (lseek(fd, offset, SEEK_SET) != offset) {
qemu_close(fd);
- g_free(cluster);
return -3;
}
}
+ cluster = g_malloc(s->cluster_size);
+
while (offset < size) {
uint32_t c1;
int rest_size = (size - offset > s->cluster_size ?
--
2.19.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] vvfat: Fix memory leak
2018-11-14 12:55 [Qemu-devel] [PATCH] vvfat: Fix memory leak Kevin Wolf
@ 2018-11-14 13:28 ` Philippe Mathieu-Daudé
2018-11-14 14:50 ` Liam Merwick
1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-11-14 13:28 UTC (permalink / raw)
To: Kevin Wolf, qemu-block; +Cc: qemu-devel, mreitz
On 14/11/18 13:55, Kevin Wolf wrote:
> Don't leak 'cluster' in the mapping == NULL case. Found by Coverity
> (CID 1055918).
>
> Fixes: 8d9401c2791ee2d2805b741b1ee3006041edcd3e
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> block/vvfat.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/block/vvfat.c b/block/vvfat.c
> index 1de5de1db4..b7b61ea8b7 100644
> --- a/block/vvfat.c
> +++ b/block/vvfat.c
> @@ -2510,7 +2510,7 @@ static int commit_one_file(BDRVVVFATState* s,
> uint32_t first_cluster = c;
> mapping_t* mapping = find_mapping_for_cluster(s, c);
> uint32_t size = filesize_of_direntry(direntry);
> - char* cluster = g_malloc(s->cluster_size);
> + char *cluster;
> uint32_t i;
> int fd = 0;
>
> @@ -2528,17 +2528,17 @@ static int commit_one_file(BDRVVVFATState* s,
> if (fd < 0) {
> fprintf(stderr, "Could not open %s... (%s, %d)\n", mapping->path,
> strerror(errno), errno);
> - g_free(cluster);
> return fd;
> }
> if (offset > 0) {
> if (lseek(fd, offset, SEEK_SET) != offset) {
> qemu_close(fd);
> - g_free(cluster);
> return -3;
> }
> }
>
> + cluster = g_malloc(s->cluster_size);
> +
> while (offset < size) {
> uint32_t c1;
> int rest_size = (size - offset > s->cluster_size ?
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] vvfat: Fix memory leak
2018-11-14 12:55 [Qemu-devel] [PATCH] vvfat: Fix memory leak Kevin Wolf
2018-11-14 13:28 ` Philippe Mathieu-Daudé
@ 2018-11-14 14:50 ` Liam Merwick
1 sibling, 0 replies; 3+ messages in thread
From: Liam Merwick @ 2018-11-14 14:50 UTC (permalink / raw)
To: Kevin Wolf, qemu-block; +Cc: mreitz, qemu-devel
On 14/11/2018 12:55, Kevin Wolf wrote:
> Don't leak 'cluster' in the mapping == NULL case. Found by Coverity
> (CID 1055918).
>
> Fixes: 8d9401c2791ee2d2805b741b1ee3006041edcd3e
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Liam Merwick <liam.merwick@oracle.com>
Thanks.
> ---
> block/vvfat.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/block/vvfat.c b/block/vvfat.c
> index 1de5de1db4..b7b61ea8b7 100644
> --- a/block/vvfat.c
> +++ b/block/vvfat.c
> @@ -2510,7 +2510,7 @@ static int commit_one_file(BDRVVVFATState* s,
> uint32_t first_cluster = c;
> mapping_t* mapping = find_mapping_for_cluster(s, c);
> uint32_t size = filesize_of_direntry(direntry);
> - char* cluster = g_malloc(s->cluster_size);
> + char *cluster;
> uint32_t i;
> int fd = 0;
>
> @@ -2528,17 +2528,17 @@ static int commit_one_file(BDRVVVFATState* s,
> if (fd < 0) {
> fprintf(stderr, "Could not open %s... (%s, %d)\n", mapping->path,
> strerror(errno), errno);
> - g_free(cluster);
> return fd;
> }
> if (offset > 0) {
> if (lseek(fd, offset, SEEK_SET) != offset) {
> qemu_close(fd);
> - g_free(cluster);
> return -3;
> }
> }
>
> + cluster = g_malloc(s->cluster_size);
> +
> while (offset < size) {
> uint32_t c1;
> int rest_size = (size - offset > s->cluster_size ?
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-11-14 14:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-14 12:55 [Qemu-devel] [PATCH] vvfat: Fix memory leak Kevin Wolf
2018-11-14 13:28 ` Philippe Mathieu-Daudé
2018-11-14 14:50 ` Liam Merwick
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).