From: Stefano Garzarella <sgarzare@redhat.com>
To: pannengyuan@huawei.com
Cc: kwolf@redhat.com, liyiting@huawei.com,
zhang.zhanghailiang@huawei.com, qemu-block@nongnu.org,
qemu-devel@nongnu.org, mreitz@redhat.com,
kuhn.chenqun@huawei.com
Subject: Re: [PATCH v5 1/2] block/nbd: extract the common cleanup code
Date: Thu, 5 Dec 2019 10:42:59 +0100 [thread overview]
Message-ID: <20191205094259.r4qb4jxcrom76x7f@steredhat> (raw)
In-Reply-To: <1575517528-44312-2-git-send-email-pannengyuan@huawei.com>
Hi Pan,
On Thu, Dec 05, 2019 at 11:45:27AM +0800, pannengyuan@huawei.com wrote:
> From: Pan Nengyuan <pannengyuan@huawei.com>
>
> The BDRVNBDState cleanup code is common in two places, add
> nbd_clear_bdrvstate() function to do these cleanups.
>
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
I only suggested this change, so I think is better to change it in:
Suggested-by: Stefano Garzarella <sgarzare@redhat.com>
Thanks,
Stefano
> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
> v3:
> - new patch, split form 2/2 patch (suggested by Stefano Garzarella)
> Changes v4 to v3:
> - replace function name from nbd_free_bdrvstate_prop to
> nbd_clear_bdrvstate and set cleared fields to NULL (suggested by Eric
> Blake)
> - remove static function prototype. (suggested by Eric Blake)
> ---
> Changes v5 to v4:
> - correct the wrong email address
> ---
> block/nbd.c | 25 +++++++++++++++----------
> 1 file changed, 15 insertions(+), 10 deletions(-)
>
> diff --git a/block/nbd.c b/block/nbd.c
> index 1239761..8b4a65a 100644
> --- a/block/nbd.c
> +++ b/block/nbd.c
> @@ -94,6 +94,19 @@ typedef struct BDRVNBDState {
>
> static int nbd_client_connect(BlockDriverState *bs, Error **errp);
>
> +void nbd_clear_bdrvstate(BDRVNBDState *s)
> +{
> + object_unref(OBJECT(s->tlscreds));
> + qapi_free_SocketAddress(s->saddr);
> + s->saddr = NULL;
> + g_free(s->export);
> + s->export = NULL;
> + g_free(s->tlscredsid);
> + s->tlscredsid = NULL;
> + g_free(s->x_dirty_bitmap);
> + s->x_dirty_bitmap = NULL;
> +}
> +
> static void nbd_channel_error(BDRVNBDState *s, int ret)
> {
> if (ret == -EIO) {
> @@ -1855,10 +1868,7 @@ static int nbd_process_options(BlockDriverState *bs, QDict *options,
>
> error:
> if (ret < 0) {
> - object_unref(OBJECT(s->tlscreds));
> - qapi_free_SocketAddress(s->saddr);
> - g_free(s->export);
> - g_free(s->tlscredsid);
> + nbd_clear_bdrvstate(s);
> }
> qemu_opts_del(opts);
> return ret;
> @@ -1937,12 +1947,7 @@ static void nbd_close(BlockDriverState *bs)
> BDRVNBDState *s = bs->opaque;
>
> nbd_client_close(bs);
> -
> - object_unref(OBJECT(s->tlscreds));
> - qapi_free_SocketAddress(s->saddr);
> - g_free(s->export);
> - g_free(s->tlscredsid);
> - g_free(s->x_dirty_bitmap);
> + nbd_clear_bdrvstate(s);
> }
>
> static int64_t nbd_getlength(BlockDriverState *bs)
> --
> 2.7.2.windows.1
>
>
--
next prev parent reply other threads:[~2019-12-05 9:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-05 3:45 [PATCH v5 0/2] block/nbd: fix memory leak in nbd_open pannengyuan
2019-12-05 3:45 ` [PATCH v5 1/2] block/nbd: extract the common cleanup code pannengyuan
2019-12-05 9:42 ` Stefano Garzarella [this message]
2019-12-05 14:04 ` Eric Blake
2020-02-25 16:51 ` Max Reitz
2020-02-26 23:25 ` Eric Blake
2019-12-05 3:45 ` [PATCH v5 2/2] block/nbd: fix memory leak in nbd_open() pannengyuan
2019-12-05 9:45 ` Stefano Garzarella
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=20191205094259.r4qb4jxcrom76x7f@steredhat \
--to=sgarzare@redhat.com \
--cc=kuhn.chenqun@huawei.com \
--cc=kwolf@redhat.com \
--cc=liyiting@huawei.com \
--cc=mreitz@redhat.com \
--cc=pannengyuan@huawei.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=zhang.zhanghailiang@huawei.com \
/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).