From nobody Tue May 7 12:36:56 2024 Delivered-To: importer@patchew.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=1606268371; cv=none; d=zohomail.com; s=zohoarc; b=lhAD/i1ffvyK26b7qUVg297M/U7bSkS+V8mwF71oiqbR9m9iP+4z6JlAwz22rby7nBvR7xqeeMds9YzcANK/3DXKImsWbN+eCxLp7G0EgqcePSd/xmYpJ00rxiza3r1aN8xaAs/qTcqnbIiSrMJxEcb14QQX1wQGpprFlwMB0RE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606268371; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=blQiIKxC34WIO3FcDNtpp4+tviIqT7MlzsJ+7i056ZM=; b=GdevzYbv8xHHaJQHtTO6lGIbnX49+VcQKRbmmghSutqM3JNWEV+W6qYRDFsjem2SirsxnmVITeTL8cep4aFKetQ4T9aNGaEOkz5KWcxyRb+YYFXPMn7YwHvN7z97QddC/VZ0yNX0Z29rSDJdONDFbkapVhNg6MUVanMly1xWSQQ= 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 1606268371848213.74877113046693; Tue, 24 Nov 2020 17:39:31 -0800 (PST) Received: from localhost ([::1]:38906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1khjmM-0002Uc-6M for importer@patchew.org; Tue, 24 Nov 2020 20:39:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59928) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1khjl4-0001av-1i; Tue, 24 Nov 2020 20:38:11 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:2156) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1khjkx-0004dp-Es; Tue, 24 Nov 2020 20:38:09 -0500 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4Cgk6B3pnTz6xTT; Wed, 25 Nov 2020 09:37:38 +0800 (CST) Received: from huawei.com (10.175.124.27) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.487.0; Wed, 25 Nov 2020 09:37:49 +0800 From: Alex Chen To: , Subject: [PATCH v2] vhost-user-scsi: Fix memleaks in vus_proc_req() Date: Wed, 25 Nov 2020 01:25:43 +0000 Message-ID: <20201125012543.109997-1-alex.chen@huawei.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-CFilter-Loop: Reflected 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; Received-SPF: pass client-ip=45.249.212.35; envelope-from=alex.chen@huawei.com; helo=szxga07-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: alex.chen@huawei.com, qemu-trivial@nongnu.org, qemu-devel@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The 'elem' is allocated memory in vu_queue_pop(), and its memory should be freed in all error branches after vu_queue_pop(). In addition, in order to free the 'elem' memory outside of while(1) loop, m= ove the definition of 'elem' to the beginning of vus_proc_req(). Reported-by: Euler Robot Signed-off-by: Alex Chen --- contrib/vhost-user-scsi/vhost-user-scsi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user= -scsi/vhost-user-scsi.c index 0f9ba4b2a2..4639440a70 100644 --- a/contrib/vhost-user-scsi/vhost-user-scsi.c +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c @@ -232,6 +232,7 @@ static void vus_proc_req(VuDev *vu_dev, int idx) VugDev *gdev; VusDev *vdev_scsi; VuVirtq *vq; + VuVirtqElement *elem =3D NULL; =20 assert(vu_dev); =20 @@ -248,7 +249,6 @@ static void vus_proc_req(VuDev *vu_dev, int idx) g_debug("Got kicked on vq[%d]@%p", idx, vq); =20 while (1) { - VuVirtqElement *elem; VirtIOSCSICmdReq *req; VirtIOSCSICmdResp *rsp; =20 @@ -288,6 +288,7 @@ static void vus_proc_req(VuDev *vu_dev, int idx) =20 free(elem); } + free(elem); } =20 static void vus_queue_set_started(VuDev *vu_dev, int idx, bool started) --=20 2.19.1