block: fix memleaks in bdrv_refresh_filename

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
This commit is contained in:
wsp1991 2020-01-16 18:15:23 +08:00
parent 01b6e5a64f
commit 7374cb0f9c
2 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,56 @@
From d09b8364d9f89c9d5f36dc983c4d4a36bb7388b9 Mon Sep 17 00:00:00 2001
From: Pan Nengyuan <pannengyuan@huawei.com>
Date: Thu, 16 Jan 2020 17:29:29 +0800
Subject: [PATCH] block: fix memleaks in bdrv_refresh_filename
If we call the qmp 'query-block' while qemu is working on 'block-commit',
it will cause memleaks. The memory leak stack is as follow:
Indirect leak of 12360 byte(s) in 3 object(s) allocated from:
#0 0x7f80f0b6d970 in __interceptor_calloc (/lib64/libasan.so.5+0xef970)
#1 0x7f80ee86049d in g_malloc0 (/lib64/libglib-2.0.so.0+0x5249d)
#2 0x55ea95b5bb67 in qdict_new /mnt/sdb/qemu/qobject/qdict.c
#3 0x55ea956cd043 in bdrv_refresh_filename /mnt/sdb/qemu/block.c
#4 0x55ea956cc950 in bdrv_refresh_filename /mnt/sdb/qemu/block.c
#5 0x55ea956cc950 in bdrv_refresh_filename /mnt/sdb/qemu/block.c
#6 0x55ea956cc950 in bdrv_refresh_filename /mnt/sdb/qemu/block.c
#7 0x55ea958818ea in bdrv_block_device_info /mnt/sdb/qemu/block/qapi.c
#8 0x55ea958879de in bdrv_query_info /mnt/sdb/qemu/block/qapi.c
#9 0x55ea9588b58f in qmp_query_block /mnt/sdb/qemu/block/qapi.c
#10 0x55ea95567392 in qmp_marshal_query_block qapi/qapi-commands-block-core.c
Indirect leak of 4120 byte(s) in 1 object(s) allocated from:
#0 0x7f80f0b6d970 in __interceptor_calloc (/lib64/libasan.so.5+0xef970)
#1 0x7f80ee86049d in g_malloc0 (/lib64/libglib-2.0.so.0+0x5249d)
#2 0x55ea95b5bb67 in qdict_new /mnt/sdb/qemu/qobject/qdict.c
#3 0x55ea956cd043 in bdrv_refresh_filename /mnt/sdb/qemu/block.c
#4 0x55ea956cc950 in bdrv_refresh_filename /mnt/sdb/qemu/block.c
#5 0x55ea956cc950 in bdrv_refresh_filename /mnt/sdb/qemu/block.c
#6 0x55ea9569f301 in bdrv_backing_attach /mnt/sdb/qemu/block.c
#7 0x55ea956a99dd in bdrv_replace_child_noperm /mnt/sdb/qemu/block.c
#8 0x55ea956b9b53 in bdrv_replace_node /mnt/sdb/qemu/block.c
#9 0x55ea956b9e49 in bdrv_append /mnt/sdb/qemu/block.c
#10 0x55ea958c3472 in commit_start /mnt/sdb/qemu/block/commit.c
#11 0x55ea94b68ab0 in qmp_block_commit /mnt/sdb/qemu/blockdev.c
Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
---
block.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/block.c b/block.c
index 9ae5c0e..52bad05 100644
--- a/block.c
+++ b/block.c
@@ -6048,6 +6048,7 @@ void bdrv_refresh_filename(BlockDriverState *bs)
child->bs->exact_filename);
pstrcpy(bs->filename, sizeof(bs->filename), child->bs->filename);
+ qobject_unref(child->bs->full_open_options);
bs->full_open_options = qobject_ref(child->bs->full_open_options);
return;
--
1.8.3.1

View File

@ -88,6 +88,7 @@ Patch0075: scsi-disk-define-props-in-scsi_block_disk-to-avoid-memleaks.patch
Patch0076: arm-translate-a64-fix-uninitialized-variable-warning.patch
Patch0077: nbd-fix-uninitialized-variable-warning.patch
Patch0078: xhci-Fix-memory-leak-in-xhci_kick_epctx-when-poweroff.patch
Patch0079: block-fix-memleaks-in-bdrv_refresh_filename.patch
BuildRequires: flex
BuildRequires: bison
@ -418,6 +419,9 @@ getent passwd qemu >/dev/null || \
%endif
%changelog
* Thu Jan 16 2020 Huawei Technologies Co., Ltd. <pannengyuan@huawei.com>
- block: fix memleaks in bdrv_refresh_filename
* Mon Jan 13 2020 Huawei Technologies Co., Ltd. <fangying1@huawei.com>
- 9pfs: Fix a possible memory leak in local_link
- scsi-disk: disk define props in scsi_block to avoid memleaks