From nobody Tue Feb 10 06:07:32 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1582516746; cv=none; d=zohomail.com; s=zohoarc; b=I3zwDhA/mVTiNHpXM7j6q/sPW9lN58FLic+zZ2N0RPEWWYmhQhJwV58tKbU2FOWuaSaF4r68oRwNAII+DwpZ+7IUid2F3Ilp8yyJ/QvV3mY3V1rV6t3dKz5ON0Akubq6GCq8k47ySj7kQ2mV5HyU4LfBIvcNjTmjLxb6VzF1OkM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582516746; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1RV5Dsj2t9EvprYZTRcgXXmhaisW3tC4jEi8yIAbhVg=; b=glFki1wlIVc47voS3xUlULNtoNUPXulg2S4Bc4c2C+c0L0+Yx1eQWqNDYFTDf8OGBB/aaPe/cnbUDAEkLzvEWvFVNMxRLWnGotTQLaTctJ0TtBp3mMz5/5XUrp9lIY0iERWuqT76pFVU/ZPNoi7HbkSFGLzhv6TsqjcESyGtrk8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582516746034827.2634509883471; Sun, 23 Feb 2020 19:59:06 -0800 (PST) Received: from localhost ([::1]:59392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j64tc-00034m-Gf for importer@patchew.org; Sun, 23 Feb 2020 22:59:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60131) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j64so-0001cV-GM for qemu-devel@nongnu.org; Sun, 23 Feb 2020 22:58:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j64sn-00065z-Du for qemu-devel@nongnu.org; Sun, 23 Feb 2020 22:58:14 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2725 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j64sk-00062g-Qu; Sun, 23 Feb 2020 22:58:11 -0500 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 68B52134498437A9FDAD; Mon, 24 Feb 2020 11:58:02 +0800 (CST) Received: from localhost.localdomain (10.175.104.216) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.439.0; Mon, 24 Feb 2020 11:57:55 +0800 From: To: , , Subject: [PATCH v2 1/2] vhost-user-blk: delete virtioqueues in unrealize to fix memleaks Date: Mon, 24 Feb 2020 12:13:35 +0800 Message-ID: <20200224041336.30790-2-pannengyuan@huawei.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20200224041336.30790-1-pannengyuan@huawei.com> References: <20200224041336.30790-1-pannengyuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.216] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.190 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pan Nengyuan , qemu-devel@nongnu.org, qemu-block@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Pan Nengyuan virtio queues forgot to delete in unrealize, and aslo error path in realize, this patch fix these memleaks, the leak stack is as follow: Direct leak of 114688 byte(s) in 16 object(s) allocated from: #0 0x7f24024fdbf0 in calloc (/lib64/libasan.so.3+0xcabf0) #1 0x7f2401642015 in g_malloc0 (/lib64/libglib-2.0.so.0+0x50015) #2 0x55ad175a6447 in virtio_add_queue /mnt/sdb/qemu/hw/virtio/virtio.c:= 2327 #3 0x55ad17570cf9 in vhost_user_blk_device_realize /mnt/sdb/qemu/hw/blo= ck/vhost-user-blk.c:419 #4 0x55ad175a3707 in virtio_device_realize /mnt/sdb/qemu/hw/virtio/virt= io.c:3509 #5 0x55ad176ad0d1 in device_set_realized /mnt/sdb/qemu/hw/core/qdev.c:8= 76 #6 0x55ad1781ff9d in property_set_bool /mnt/sdb/qemu/qom/object.c:2080 #7 0x55ad178245ae in object_property_set_qobject /mnt/sdb/qemu/qom/qom-= qobject.c:26 #8 0x55ad17821eb4 in object_property_set_bool /mnt/sdb/qemu/qom/object.= c:1338 #9 0x55ad177aeed7 in virtio_pci_realize /mnt/sdb/qemu/hw/virtio/virtio-= pci.c:1801 Reported-by: Euler Robot Signed-off-by: Pan Nengyuan Reviewed-by: Stefan Hajnoczi --- v2->v1: There is no change in this patch(only change the patch2/2) --- hw/block/vhost-user-blk.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index d8c459c575..2eba8b9db0 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -460,6 +460,9 @@ reconnect: virtio_err: g_free(s->vqs); g_free(s->inflight); + for (i =3D 0; i < s->num_queues; i++) { + virtio_del_queue(vdev, i); + } virtio_cleanup(vdev); vhost_user_cleanup(&s->vhost_user); } @@ -468,6 +471,7 @@ static void vhost_user_blk_device_unrealize(DeviceState= *dev, Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VHostUserBlk *s =3D VHOST_USER_BLK(dev); + int i; =20 virtio_set_status(vdev, 0); qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, NULL, @@ -476,6 +480,10 @@ static void vhost_user_blk_device_unrealize(DeviceStat= e *dev, Error **errp) vhost_dev_free_inflight(s->inflight); g_free(s->vqs); g_free(s->inflight); + + for (i =3D 0; i < s->num_queues; i++) { + virtio_del_queue(vdev, i); + } virtio_cleanup(vdev); vhost_user_cleanup(&s->vhost_user); } --=20 2.18.2