From nobody Mon Feb 9 08:10:28 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; 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=1579764003; cv=none; d=zohomail.com; s=zohoarc; b=ih/kylQmssJvyONJuceE6/QOPUCcaVtABTilRAvNwYX64M/bBD3HlFQetMxr0AsUz7bOrvNZr/+x9tOkWt0EJuY3Jha4wB5ce4HdOgDlb0DY12cXJtyLqrY5yR8IsMrrrkxafsGuuzQ1mgpyAINaCys5dBku1w+6c/TqPXeEZcg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579764003; 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=EE2u/AAZTtiTF3BR1usKNAN0L1IlKKsiavRWKotl39g=; b=TayIVqFw/W4E/onwAqfv4kusfcJJfoM4W0o+DTVLV+b5n5K6VHPqNNxOgde5W3x4OO+9SA4b++J/iwmUViv9DaUqRgYFSGIThxgwPntSEo7uPZZAgdTxiNOjSUvzTZzSXjkFsMD/i5hJGUErJ0TFa6RWoiwz204XXCSx+U6SVVc= 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 157976400311132.552423684169185; Wed, 22 Jan 2020 23:20:03 -0800 (PST) Received: from localhost ([::1]:52110 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuWmX-00080p-Uz for importer@patchew.org; Thu, 23 Jan 2020 02:20:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37466) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuWdh-0006Q6-9S for qemu-devel@nongnu.org; Thu, 23 Jan 2020 02:10:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iuWdf-0008Lo-2q for qemu-devel@nongnu.org; Thu, 23 Jan 2020 02:10:53 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:26573 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iuWde-0008LF-Va for qemu-devel@nongnu.org; Thu, 23 Jan 2020 02:10:51 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-364-EKs5JKD7Myah2lhb6VqUXQ-1; Thu, 23 Jan 2020 02:10:48 -0500 Received: by mail-wm1-f69.google.com with SMTP id b133so609745wmb.2 for ; Wed, 22 Jan 2020 23:10:48 -0800 (PST) Received: from redhat.com (bzq-79-176-0-156.red.bezeqint.net. [79.176.0.156]) by smtp.gmail.com with ESMTPSA id g79sm509792wme.17.2020.01.22.23.10.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 23:10:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579763450; 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=EE2u/AAZTtiTF3BR1usKNAN0L1IlKKsiavRWKotl39g=; b=G6J0SbNSvA21i+nNmKZ+/Sb9jdy6jbMHKkIIsnfv0zVZigVJtt6DU1FZtaRhs/wJrkrv0d eJyWYsDjIugyORduf6L0gnPvHC67gqcslxq9bnfDuCwQz1JnQvm4y6F8MGcxKA42iTvQHo nlhVEfv5cNuVG6cNdjjb+CjV3O7gnSo= 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=uL+2BTDQ25Kv4JEooHriCyXb60bUBMFr6mqaTgyAVpc=; b=fDqw4KfQW5irpq+K4XV4nXVy97dz7MTzP3LOyjNzZgjrEc7sLzGxoR6MQFijE6u2fy ZheYQaqbj+IO5HUPzGAS9fiLKPue8HA9miDbfpdqcLBwgCwFnP+jvufgW2jATuS9hm6m 6UEGyFDu7fI4HGWTdjX5m5/etRIf9ICtio+VpdRH1KG0D0iWFyaOjR9pxFcMyF1qdLdg 7srfKQ3F+3kyzkgOtXGF9ucLEmoHIRFNv2vE7cB85IPhnvp9yg7Nbbj+6V3gemtinNBD 9jTAzGVWH2ECn8GR5z3SsC0QjvHJOicasZDz5tVDoUCJx8SyClHDuwAjrz0US/xuEJ+g nOVA== X-Gm-Message-State: APjAAAXrJ27JrP5o9exGtLxZSHW4kmkGL/rdY4A/n0lLI9BEkamK2Tbf xWrdbv0pmOq9JdBC3lFuSntP15BlH5q8FqpW21OlvkJeS5RfYBStcndpjnzzX6mrJMf9sqCAAVB vGOyfJWDEfRhke54= X-Received: by 2002:a7b:c3d7:: with SMTP id t23mr2487223wmj.33.1579763447168; Wed, 22 Jan 2020 23:10:47 -0800 (PST) X-Google-Smtp-Source: APXvYqwD24tbLy1+JPJJtuocF4uodx6o5eIxJ5Vkykd56QNSfLvaEcY5VJOaQU5Lv38VDSWD6/9LaQ== X-Received: by 2002:a7b:c3d7:: with SMTP id t23mr2487208wmj.33.1579763446957; Wed, 22 Jan 2020 23:10:46 -0800 (PST) Date: Thu, 23 Jan 2020 02:10:44 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v3 12/18] virtio-scsi: delete vqs in unrealize to avoid memleaks Message-ID: <20200123070913.626488-13-mst@redhat.com> References: <20200123070913.626488-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200123070913.626488-1-mst@redhat.com> X-Mailer: git-send-email 2.24.1.751.gd10ce2899c X-Mutt-Fcc: =sent X-MC-Unique: EKs5JKD7Myah2lhb6VqUXQ-1 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] X-Received-From: 205.139.110.61 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: Fam Zheng , Peter Maydell , Pan Nengyuan , Stefan Hajnoczi , Euler Robot , Paolo Bonzini 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 This patch fix memleaks when attaching/detaching virtio-scsi device, the memory leak stack is as follow: Direct leak of 21504 byte(s) in 3 object(s) allocated from: #0 0x7f491f2f2970 (/lib64/libasan.so.5+0xef970) ??:? #1 0x7f491e94649d (/lib64/libglib-2.0.so.0+0x5249d) ??:? #2 0x564d0f3919fa (./x86_64-softmmu/qemu-system-x86_64+0x2c3e9fa) /mnt/s= db/qemu/hw/virtio/virtio.c:2333 #3 0x564d0f2eca55 (./x86_64-softmmu/qemu-system-x86_64+0x2b99a55) /mnt/s= db/qemu/hw/scsi/virtio-scsi.c:912 #4 0x564d0f2ece7b (./x86_64-softmmu/qemu-system-x86_64+0x2b99e7b) /mnt/s= db/qemu/hw/scsi/virtio-scsi.c:924 #5 0x564d0f39ee47 (./x86_64-softmmu/qemu-system-x86_64+0x2c4be47) /mnt/s= db/qemu/hw/virtio/virtio.c:3531 #6 0x564d0f980224 (./x86_64-softmmu/qemu-system-x86_64+0x322d224) /mnt/s= db/qemu/hw/core/qdev.c:865 Reported-by: Euler Robot Signed-off-by: Pan Nengyuan Message-Id: <20200117075547.60864-2-pannengyuan@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Stefan Hajnoczi --- hw/scsi/virtio-scsi.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 4bc73a370e..858b3aaccb 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -943,7 +943,13 @@ void virtio_scsi_common_unrealize(DeviceState *dev) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(dev); + int i; =20 + virtio_del_queue(vdev, 0); + virtio_del_queue(vdev, 1); + for (i =3D 0; i < vs->conf.num_queues; i++) { + virtio_del_queue(vdev, i + 2); + } g_free(vs->cmd_vqs); virtio_cleanup(vdev); } --=20 MST