qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Daniella Lee <daniellalee111@gmail.com>
To: kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org,
	qemu-devel@nongnu.org
Cc: Daniella Lee <daniellalee111@gmail.com>, pai.po.sec@gmail.com
Subject: [PATCH] block vvfat.c fix leak when failure occurs
Date: Fri, 19 Nov 2021 19:25:53 +0800	[thread overview]
Message-ID: <20211119112553.352222-1-daniellalee111@gmail.com> (raw)
In-Reply-To: <d02640d5-7c6c-f78b-da6a-0cad1d53d80f@redhat.com>

Based on your suggestions. I made a new patch which contians:
1.format detection
2.replace calloc with g_malloc0 in enable_write_target function
3.use g_free without null pointer detection in vvfat_open function
4.delete line "ret = 0", use return ret directly in vvfat_open function


Signed-off-by: Daniella Lee <daniellalee111@gmail.com>
---
 block/vvfat.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/block/vvfat.c b/block/vvfat.c
index 05e78e3c27..5dacc6cfac 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -1279,8 +1279,18 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
 
     qemu_co_mutex_init(&s->lock);
 
-    ret = 0;
+    qemu_opts_del(opts);
+
+    return 0;
+
 fail:
+    g_free(s->qcow_filename);
+    s->qcow_filename = NULL;
+    g_free(s->cluster_buffer);
+    s->cluster_buffer = NULL;
+    g_free(s->used_clusters);
+    s->used_clusters = NULL;
+
     qemu_opts_del(opts);
     return ret;
 }
@@ -3118,7 +3128,7 @@ static int enable_write_target(BlockDriverState *bs, Error **errp)
     int size = sector2cluster(s, s->sector_count);
     QDict *options;
 
-    s->used_clusters = calloc(size, 1);
+    s->used_clusters = g_malloc0(size);
 
     array_init(&(s->commits), sizeof(commit_t));
 
@@ -3166,8 +3176,6 @@ static int enable_write_target(BlockDriverState *bs, Error **errp)
     return 0;
 
 err:
-    g_free(s->qcow_filename);
-    s->qcow_filename = NULL;
     return ret;
 }
 
-- 
2.17.1



  reply	other threads:[~2021-11-19 11:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-16 12:57 [PATCH] block/vvfat.c fix leak when failure occurs Daniella Lee
2021-11-18  8:34 ` Hanna Reitz
     [not found]   ` <CAH1re1FV07jaUF9xQZn-spX0A+rwdebWvm0LXdaAqBWDocvGcw@mail.gmail.com>
2021-11-18 14:51     ` Hanna Reitz
2021-11-19 11:25       ` Daniella Lee [this message]
2021-11-23  8:57         ` [PATCH] block vvfat.c " Hanna Reitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211119112553.352222-1-daniellalee111@gmail.com \
    --to=daniellalee111@gmail.com \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pai.po.sec@gmail.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).