Skip to contentSkip to conversation

block: Fix leak of BdrvIoctlCompletionData when driver returns NULL

PATCH In review Fam Zheng 2 participants 3 messages May 31, 2016 Block layer

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH 1/1 block: Fix leak of BdrvIoctlCompletionData when driver returns NULL

"data" allocated in bdrv_co_do_ioctl is not freed. Free it before returning.

---
 block/io.c | 1 +
 1 file changed, 1 insertion(+)
block/io.c +1 -0
index 2d832aa..aa5a5d7 100644
@@ -2320,6 +2320,7 @@ static void bdrv_ioctl_bh_cb(void *opaque)
 
     bdrv_co_io_em_complete(data->co, -ENOTSUP);
     qemu_bh_delete(data->bh);
+    g_free(data);
 }
 
 static int bdrv_co_do_ioctl(BlockDriverState *bs, int req, void *buf)
Signature · 1 line
2.8.3
#1 lore raw
Quoted 16 lines · Fam Zheng

"data" allocated in bdrv_co_do_ioctl is not freed. Free it before returning.

---
 block/io.c | 1 +
 1 file changed, 1 insertion(+)
block/io.c +0 -0
index 2d832aa..aa5a5d7 100644

block/io.c static void bdrv_ioctl_bh_cb(void *opaque) · line 2326

Quoted 7 lines
block/io.c +1 -0
@@ -2320,6 +2320,7 @@ static void bdrv_ioctl_bh_cb(void *opaque)
 
     bdrv_co_io_em_complete(data->co, -ENOTSUP);
     qemu_bh_delete(data->bh);
+    g_free(data);
 }
 
 static int bdrv_co_do_ioctl(BlockDriverState *bs, int req, void *buf)

Is the bottom half needed at all? Why can't you just do "co.ret = -ENOTSUP;"? The bottom half indirection is not needed for coroutine functions, only for bdrv_aio_*; and bdrv_co_maybe_schedule_bh already provides it.

Thanks,

Paolo

author
#2 lore raw
Quoted 24 lines · Paolo Bonzini
Quoted 21 lines · Fam Zheng

"data" allocated in bdrv_co_do_ioctl is not freed. Free it before returning.

---
 block/io.c | 1 +
 1 file changed, 1 insertion(+)
block/io.c +1 -0
index 2d832aa..aa5a5d7 100644
@@ -2320,6 +2320,7 @@ static void bdrv_ioctl_bh_cb(void *opaque)
 
     bdrv_co_io_em_complete(data->co, -ENOTSUP);
     qemu_bh_delete(data->bh);
+    g_free(data);
 }
 
Quoted 8 lines

block/io.c static void bdrv_ioctl_bh_cb(void *opaque) · line 2326

Quoted 2 lines
block/io.c +0 -0
 static int bdrv_co_do_ioctl(BlockDriverState *bs, int req, void *buf)

Is the bottom half needed at all? Why can't you just do "co.ret = -ENOTSUP;"? The bottom half indirection is not needed for coroutine functions, only for bdrv_aio_*; and bdrv_co_maybe_schedule_bh already provides it.

You are right, I missed that. Let's drop the BH.

Fam