From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17B59C2D0E4 for ; Tue, 24 Nov 2020 15:39:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 510AC2067C for ; Tue, 24 Nov 2020 15:39:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VlWcPZHE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 510AC2067C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:48894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1khaPK-0007vw-Dl for qemu-devel@archiver.kernel.org; Tue, 24 Nov 2020 10:39:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34648) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1khaOQ-0007NF-FL; Tue, 24 Nov 2020 10:38:10 -0500 Received: from mail-ot1-x342.google.com ([2607:f8b0:4864:20::342]:38294) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1khaOO-0003A4-Jy; Tue, 24 Nov 2020 10:38:10 -0500 Received: by mail-ot1-x342.google.com with SMTP id 92so16652310otd.5; Tue, 24 Nov 2020 07:38:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=T9aximfDkcbO+2+ihjXsHELH/uw7Ph7PjKl7o2wstDs=; b=VlWcPZHEeP7yIr6paGUhRSRchx/CZ7Hgu6UWYi/FjGF3ll7b0WgxSV41fJZyHax6HK QTHKDS+axtFHWAyKGQLVTWsYiYogWs+q1S3uIkBE6oitfWtoP6FbJat+cCYZFs0NgISy QxLVRDBqjFNSz9l30IyS0z56e1JDXWVai11IInX5L4IKf46p2E1Q2+Quuph0kL6qCHqC PIyM6u3loW+ub9GWro4aLPY9TFwDifqCYkF5zC8A1wl3RE4oce/+ILoYmyJwEK/dwqYj 6n8NtAmTg1Ei4zjB9+/7rQDQMqd9OS+IMFmsDhYBjVJIBiYrrLVsMKS3BgRMatahZQKm 9Krg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=T9aximfDkcbO+2+ihjXsHELH/uw7Ph7PjKl7o2wstDs=; b=HXRQtYlt1LyhvUpz/83N6O/FPEkqbO/ZYakpnjBpzlRPqe8TG6BGQMiGXasFzkRMwI qqFlvIPEJmLCAE/W2dwaEf7gMfylo0ByhVLSnvnSnfcuNOMJ9NcVxrRW1oDQ55sbe6DW 4daOQ+ZBJwFhRNBCHm/MLtbNidQMCfIww7sT+cpxDIlUXF1b6U58rjCOhn+b6Xqo089a B/oFU7rtXZlT60OJbb9lE1ZzJ65j2KgDt+zk2amb9HE/1h5PuMUz/zXuniMn1w1eU15P K/ejtV3gBthQR18b/AUdpTeDdMyqMlgx349iY7JWyyn8WiKhWXl1O5R5PtUMyCQsy2j+ v4+Q== X-Gm-Message-State: AOAM53151M+lFSpFaO6MU7sulgtwFWCQ5TiXoHHz38NTJGQEvRHliI8h xHpf/++OvBf+5onkpYl17ufdyMGNsIxa6/+DSpk= X-Google-Smtp-Source: ABdhPJzHyu+wOhvPtYmSG6qGRzIeV/2pAWwc43pwGaIu6xa1ica19HcnW6AkFi8TvGd/UU8j+nK721Ph5z9UhaWBQnQ= X-Received: by 2002:a9d:27e8:: with SMTP id c95mr3784442otb.262.1606232286750; Tue, 24 Nov 2020 07:38:06 -0800 (PST) MIME-Version: 1.0 References: <20201124143727.47037-1-alex.chen@huawei.com> In-Reply-To: <20201124143727.47037-1-alex.chen@huawei.com> From: Raphael Norwitz Date: Tue, 24 Nov 2020 10:37:55 -0500 Message-ID: Subject: Re: [PATCH] vhost-user-scsi: Fix memleaks in vus_proc_req() To: Alex Chen Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2607:f8b0:4864:20::342; envelope-from=raphael.s.norwitz@gmail.com; helo=mail-ot1-x342.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: qemu-trivial@nongnu.org, zhang.zhanghailiang@huawei.com, Raphael Norwitz , QEMU , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Tue, Nov 24, 2020 at 9:50 AM Alex Chen wrote: > > The 'elem' is allocated memory in vu_queue_pop(), and it's memory should be > freed in all error branchs after vu_queue_pop(). s/branchs/branches > In addition, in order to free 'elem' memory outside of while(1) loop, move the > definition of 'elem' to the begin of vus_proc_req(). s/begin/beginning > > Reported-by: Euler Robot > Signed-off-by: Alex Chen Other than spelling in the commit message, looks good to me. Reviewed-by: Raphael Norwitz > --- > 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 = NULL; > > assert(vu_dev); > > @@ -248,7 +249,6 @@ static void vus_proc_req(VuDev *vu_dev, int idx) > g_debug("Got kicked on vq[%d]@%p", idx, vq); > > while (1) { > - VuVirtqElement *elem; > VirtIOSCSICmdReq *req; > VirtIOSCSICmdResp *rsp; > > @@ -288,6 +288,7 @@ static void vus_proc_req(VuDev *vu_dev, int idx) > > free(elem); > } > + free(elem); > } > > static void vus_queue_set_started(VuDev *vu_dev, int idx, bool started) > -- > 2.19.1 > >