From nobody Thu Nov 13 21:51:51 2025 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; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582708098; cv=none; d=zohomail.com; s=zohoarc; b=HH1tbhuLzER5fHzXa92L7+67yUrf+sxA4/JPsDhgNccvGLCmi6AZsLtUT0GMOUKbq7ZOvG3ocyGMVrfyVYjge64gCwYYudW3Jd6x1hFcxABPT4330Cb5sF2hl7i1JDXg20dmYD0oavKeDMxP6fsFFU4zC8xXcNhOHJUQnek7Iv8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582708098; h=Content-Type:Content-Transfer-Encoding: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=NjdfC5cPcTj7xCSppU7CRy3um06hUEk/RHvT4NHcJJM=; b=TEWZ3YMpW9f3B8eRjHJSei3dRlcmBqH4CZ97dQoe3GiBZ9SuWX8fwwEHuXcJpJEX3/RxptiJQQpPgKHKrRT4QzSAW4ixACYGoDc4T2aZf7AxAWF6WwDgIP88zUDuH0A1bnfTPew71+PrFKkgqhUQZU6K9UAUyLfsKW6alQ9wygY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582708098597635.5816454116755; Wed, 26 Feb 2020 01:08:18 -0800 (PST) Received: from localhost ([::1]:40498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6sfx-0006fc-FB for importer@patchew.org; Wed, 26 Feb 2020 04:08:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58685) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6se4-0003Zr-H1 for qemu-devel@nongnu.org; Wed, 26 Feb 2020 04:06:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6se3-00077I-AW for qemu-devel@nongnu.org; Wed, 26 Feb 2020 04:06:20 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:37610 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6se3-00076t-6L for qemu-devel@nongnu.org; Wed, 26 Feb 2020 04:06:19 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-357-0cMcsbPeMF2BfRRCLZ6jWg-1; Wed, 26 Feb 2020 04:06:16 -0500 Received: by mail-wm1-f72.google.com with SMTP id f9so381566wmb.2 for ; Wed, 26 Feb 2020 01:06:16 -0800 (PST) Received: from redhat.com (bzq-79-178-2-214.red.bezeqint.net. [79.178.2.214]) by smtp.gmail.com with ESMTPSA id n3sm720576wmc.42.2020.02.26.01.06.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 01:06:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582707978; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NjdfC5cPcTj7xCSppU7CRy3um06hUEk/RHvT4NHcJJM=; b=AwN7xygvDpzNWObnYOvVFDtcqvtCJYk4HeDwV3VRzzQRDX+39QFa/QRtslmTVRi1Wni0D+ mOnOJGuclL3yHsUiFD6j53Y8r9Ja9PCP8ZMVbBxBYwZG2KBlb2GJy7poIL2YCm8zcOpZMp 0gX/w0O8YE1ZqaFZWp8F1PbAP47k710= X-MC-Unique: 0cMcsbPeMF2BfRRCLZ6jWg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=yx/d9Pi1yF7zdpvYgnvi6Hx1i6BxcPVN8IeOoA2COOE=; b=jrXMsYDR5u/Fj3REWc7WsNVI5v5ngfV24rroE0bhTthKYv3Q6UmVbzGmLfoovc9x7Y KnTAdgImQx/LDvgGNkuIvLswUextUhFgD+R+UdXfgsJHmr7CWWcAT1nEg9JWSvPHIm9Y 1J7ucRsPKcEzE/6keVczqmn09xLwuc4o8tHGnD56nDvuqEkq6xbHPw3Bct9nzHsgZwzf AU8KDNIAlZCiWdaflau3L/ci83CwG6mXXF13PLvCiQ7NWHXLs9IH8idpDgvhk0hXuICI ZfDPf6sptzCzh4fVJvN15PQ51k0mM2iuh93ZAkyz1FLIDkuyhIjdg4KcyCToLoEtLNgc LKfQ== X-Gm-Message-State: APjAAAXjQgTMn+9qlbNq72PzHV5fezy6QD1RAIA+3Jdu7CSi+5H3romP qE4HHNLquINiYjl1p/yjM2QCuOoYFS2LmwOLdXQghpVRtqbDS9qdcrQi2FSUa008TbEZ6ihgGXj 8+aXHR5laZ/Th9xA= X-Received: by 2002:a05:6000:1046:: with SMTP id c6mr472005wrx.411.1582707975395; Wed, 26 Feb 2020 01:06:15 -0800 (PST) X-Google-Smtp-Source: APXvYqwcBOPUZwYDu5Z1jlTNJE8V2+fh2gTwcPKC0Dvp/M77eGbLOJnS+la66Co8BhtdPey+grHRPQ== X-Received: by 2002:a05:6000:1046:: with SMTP id c6mr471972wrx.411.1582707975165; Wed, 26 Feb 2020 01:06:15 -0800 (PST) Date: Wed, 26 Feb 2020 04:06:13 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 09/30] vhost-user-blk: delete virtioqueues in unrealize to fix memleaks Message-ID: <20200226090010.708934-10-mst@redhat.com> References: <20200226090010.708934-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200226090010.708934-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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: Kevin Wolf , Peter Maydell , qemu-block@nongnu.org, Pan Nengyuan , Max Reitz , Stefan Hajnoczi , Euler Robot Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 Message-Id: <20200224041336.30790-2-pannengyuan@huawei.com> Reviewed-by: Stefan Hajnoczi Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- 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 MST