From nobody Thu Nov 13 12:01:34 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=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579799618; cv=none; d=zohomail.com; s=zohoarc; b=dfI8qfVLP0u4v9DBlWGkquHKwAc/UBRjb3wvI/vC+acoqAHrhg2gxCNT20P3kM1oa551ygj2qYmRQLIKi2zuf3bznznIeqK1azD0BnqX8Jd5stnGS6h+CiedX7fC7OKGPPSU7gKYfi6y/gKH5JCSAwhB7IIcTn4R94+bJLkxbLY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579799618; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=VSNPfn/WqEe4auVK0p1YkDtx0JRhgePqKKnBaAQWvqk=; b=ee+Sfci47tlmq0xb5iR2QQGahCl88g3G7yGiBV39Za6cIgWkM6FCXmmBNpUKUVdFhRYSjKyoRF3hokYegi+N1xX//PkBERWP50FXB4jX6nA+H2AO2E3UmtepnYHFvteG/UIp0VECzVkw/5ymBmCJzP59ZmzvPaASqnBUrKxQ4kU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1579799618275158.20751026622156; Thu, 23 Jan 2020 09:13:38 -0800 (PST) Received: from localhost ([::1]:33138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iug2z-0000M0-6K for importer@patchew.org; Thu, 23 Jan 2020 12:13:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52542) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuctV-0008MN-H2 for qemu-devel@nongnu.org; Thu, 23 Jan 2020 08:51:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iuctU-00085s-Al for qemu-devel@nongnu.org; Thu, 23 Jan 2020 08:51:37 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:52142 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 1iuctU-00084k-8K for qemu-devel@nongnu.org; Thu, 23 Jan 2020 08:51:36 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-7-HolpI--ZOj-YSJq9mU4p3Q-1; Thu, 23 Jan 2020 08:51:32 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 63F0CDBAD; Thu, 23 Jan 2020 13:51:31 +0000 (UTC) Received: from 640k.localdomain.com (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 602A8857A9; Thu, 23 Jan 2020 13:51:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579787496; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VSNPfn/WqEe4auVK0p1YkDtx0JRhgePqKKnBaAQWvqk=; b=XgQoJ9NEyPndoBIjc4a7ppOmWpAIGBT21tKwYOCUBFEbNncMZE7uxEVSGCeSohVtdJ2ZFs g7Rz9BU4uu1i0HESN6oQBuv9sT48Tg5Xh8q9LROtwKhChoRuzmOHRHlRgVSqCF1+j29lYJ 9VwFLvmyBpBgoBKH8WHbdPJvwkjc5yE= From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 21/59] virtio-scsi: delete vqs in unrealize to avoid memleaks Date: Thu, 23 Jan 2020 14:50:11 +0100 Message-Id: <1579787449-27599-22-git-send-email-pbonzini@redhat.com> In-Reply-To: <1579787449-27599-1-git-send-email-pbonzini@redhat.com> References: <1579787449-27599-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: HolpI--ZOj-YSJq9mU4p3Q-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 207.211.31.81 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 Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) MIME-Version: 1.0 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 Reviewed-by: Stefan Hajnoczi Message-Id: <20200117075547.60864-2-pannengyuan@huawei.com> Signed-off-by: Paolo Bonzini --- 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 4bc73a3..858b3aa 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 1.8.3.1