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=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_2 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 A00FFC56202 for ; Thu, 26 Nov 2020 12:11:51 +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 A4F2E2087C for ; Thu, 26 Nov 2020 12:11:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A4F2E2087C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kiG7p-0003hb-Gz for qemu-devel@archiver.kernel.org; Thu, 26 Nov 2020 07:11:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49178) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kiG3q-0002BT-5Z for qemu-devel@nongnu.org; Thu, 26 Nov 2020 07:07:42 -0500 Received: from 8.mo52.mail-out.ovh.net ([46.105.37.156]:51641) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kiG3n-0002Fi-OY for qemu-devel@nongnu.org; Thu, 26 Nov 2020 07:07:41 -0500 Received: from mxplan5.mail.ovh.net (unknown [10.109.156.137]) by mo52.mail-out.ovh.net (Postfix) with ESMTPS id A359B1FEC5F; Thu, 26 Nov 2020 13:07:35 +0100 (CET) Received: from kaod.org (37.59.142.96) by DAG8EX1.mxp5.local (172.16.2.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2044.4; Thu, 26 Nov 2020 13:07:35 +0100 Authentication-Results: garm.ovh; auth=pass (GARM-96R0017a8ab3fb-4e31-460a-8f95-ed6f7cb74178, 3D9671329B6E73EAAA72C004E5562AE56C463AC8) smtp.auth=groug@kaod.org Date: Thu, 26 Nov 2020 13:07:34 +0100 From: Greg Kurz To: Alex Chen Subject: Re: [PATCH] virtfs-proxy-helper: Fix a resource leak in main() Message-ID: <20201126130734.56f2a84a@bahia.lan> In-Reply-To: <20201126101624.55714-1-alex.chen@huawei.com> References: <20201126101624.55714-1-alex.chen@huawei.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [37.59.142.96] X-ClientProxiedBy: DAG3EX1.mxp5.local (172.16.2.21) To DAG8EX1.mxp5.local (172.16.2.71) X-Ovh-Tracer-GUID: 12e4a73d-b486-4a6b-addd-d533006ebef0 X-Ovh-Tracer-Id: 11134868607857695139 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedujedrudehvddgfeejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepfffhvffukfgjfhfogggtgfhisehtjeertdertddvnecuhfhrohhmpefirhgvghcumfhurhiiuceoghhrohhugheskhgrohgurdhorhhgqeenucggtffrrghtthgvrhhnpeefuddtieejjeevheekieeltefgleetkeetheettdeifeffvefhffelffdtfeeljeenucfkpheptddrtddrtddrtddpfeejrdehledrudegvddrleeinecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmohguvgepshhmthhpqdhouhhtpdhhvghlohepmhigphhlrghnhedrmhgrihhlrdhovhhhrdhnvghtpdhinhgvtheptddrtddrtddrtddpmhgrihhlfhhrohhmpehgrhhouhhgsehkrghougdrohhrghdprhgtphhtthhopeiihhgrnhhgrdiihhgrnhhghhgrihhlihgrnhhgsehhuhgrfigvihdrtghomh Received-SPF: pass client-ip=46.105.37.156; envelope-from=groug@kaod.org; helo=8.mo52.mail-out.ovh.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, 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, qemu_oss@crudebyte.com, qemu-devel@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Thu, 26 Nov 2020 10:16:24 +0000 Alex Chen wrote: > Only one of the options -s and -f can be used. When -f is used, > the fd is created externally and does not need to be closed. The process running virtfs-proxy-helper has its own copy of the fd inherited from its parent. And this fd will be closed eventually when the process terminates. > When -s is used, a new socket fd is created, and this socket fd > needs to be closed at the end of main(). > Same here, the new socket fd is closed when the process terminates. The only justification to merge such a change would be if the code was sitting in some other function, in which case we should indeed do proper rollback. But it is main() here, so this patch isn't needed. > Reported-by: Euler Robot Can you provide a copy of the report in case I'm missing something ? > Signed-off-by: Alex Chen > --- > fsdev/virtfs-proxy-helper.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c > index 15c0e79b06..339d477169 100644 > --- a/fsdev/virtfs-proxy-helper.c > +++ b/fsdev/virtfs-proxy-helper.c > @@ -1154,6 +1154,9 @@ int main(int argc, char **argv) > process_requests(sock); > error: > g_free(rpath); > + if (sock_name) { > + close(sock); > + } > g_free(sock_name); > do_log(LOG_INFO, "Done\n"); > closelog();