qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V3 1/2] block/nbd: extract the common cleanup code
@ 2019-11-29  7:25 pannengyuan
  2019-11-29  7:25 ` [PATCH V3 2/2] block/nbd: fix memory leak in nbd_open() pannengyuan
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: pannengyuan @ 2019-11-29  7:25 UTC (permalink / raw)
  To: eblake, kwolf, mreitz, sgarzare
  Cc: liyiting, zhang.zhanghailiang, qemu-block, PanNengyuan,
	qemu-devel, kuhn.chenqun

From: PanNengyuan <pannengyuan@huawei.com>

The BDRVNBDState cleanup code is common in two places, add
nbd_free_bdrvstate_prop() function to do these cleanups (suggested by
Stefano Garzarella).

Signed-off-by: PanNengyuan <pannengyuan@huawei.com>
---
 block/nbd.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/block/nbd.c b/block/nbd.c
index 1239761..5805979 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -94,6 +94,8 @@ typedef struct BDRVNBDState {
 
 static int nbd_client_connect(BlockDriverState *bs, Error **errp);
 
+static void nbd_free_bdrvstate_prop(BDRVNBDState *s);
+
 static void nbd_channel_error(BDRVNBDState *s, int ret)
 {
     if (ret == -EIO) {
@@ -1486,6 +1488,15 @@ static int nbd_client_connect(BlockDriverState *bs, Error **errp)
     }
 }
 
+static void nbd_free_bdrvstate_prop(BDRVNBDState *s)
+{
+    object_unref(OBJECT(s->tlscreds));
+    qapi_free_SocketAddress(s->saddr);
+    g_free(s->export);
+    g_free(s->tlscredsid);
+    g_free(s->x_dirty_bitmap);
+}
+
 /*
  * Parse nbd_open options
  */
@@ -1855,10 +1866,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_free_bdrvstate_prop(s);
     }
     qemu_opts_del(opts);
     return ret;
@@ -1937,12 +1945,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_free_bdrvstate_prop(s);
 }
 
 static int64_t nbd_getlength(BlockDriverState *bs)
-- 
2.7.2.windows.1




^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-12-04  7:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-29  7:25 [PATCH V3 1/2] block/nbd: extract the common cleanup code pannengyuan
2019-11-29  7:25 ` [PATCH V3 2/2] block/nbd: fix memory leak in nbd_open() pannengyuan
2019-12-03 17:52   ` for 4.2 ??? " Vladimir Sementsov-Ogievskiy
2019-12-03 18:54     ` Eric Blake
2019-12-03 21:59       ` Eric Blake
2019-12-04  3:30       ` pannengyuan
2019-12-03 17:38 ` [PATCH V3 1/2] block/nbd: extract the common cleanup code Vladimir Sementsov-Ogievskiy
2019-12-04  3:12   ` pannengyuan
2019-12-04  7:19     ` Vladimir Sementsov-Ogievskiy
2019-12-04  7:24       ` Pan Nengyuan
2019-12-03 19:00 ` Eric Blake
2019-12-04  3:20   ` pannengyuan

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).