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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7899C6FA8F for ; Wed, 30 Aug 2023 18:47:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242092AbjH3SrB (ORCPT ); Wed, 30 Aug 2023 14:47:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242560AbjH3JB7 (ORCPT ); Wed, 30 Aug 2023 05:01:59 -0400 Received: from smtp-190e.mail.infomaniak.ch (smtp-190e.mail.infomaniak.ch [IPv6:2001:1600:4:17::190e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B90F1CC9 for ; Wed, 30 Aug 2023 02:01:53 -0700 (PDT) Received: from smtp-3-0001.mail.infomaniak.ch (unknown [10.4.36.108]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4RbJFW2w2VzMqSYV; Wed, 30 Aug 2023 09:01:51 +0000 (UTC) Received: from unknown by smtp-3-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4RbJFV6lhYzMpp9y; Wed, 30 Aug 2023 11:01:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1693386111; bh=GPuobfew1UhhdtqGSwSghFtfdXBk0VcPKhAtepB/RTQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=o1bRc4GkTkSUL/c1YwpOHDzHtq0/J3LM4hmcOG9H7JEuR37BFeK1khzjwlKpgoC+x 2kh+DS9foGoCP7Lef8MAhV3iBtVjRws/N/bNsBxTxNgs9aYBPqZDxxCP5RjPzT/RSg x8KcJ3O6FnvaS+tGwebfCE0jMZuIN8GPsy/cU3Tg= Date: Wed, 30 Aug 2023 11:01:47 +0200 From: =?utf-8?Q?Micka=C3=ABl_Sala=C3=BCn?= To: Ding Xiang Cc: shuah@kernel.org, linux-security-module@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] selftests/landlock: Fix a resource leak Message-ID: <20230830.Ahqu4iepha4I@digikod.net> References: <20230830060858.2841-1-dingxiang@cmss.chinamobile.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230830060858.2841-1-dingxiang@cmss.chinamobile.com> X-Infomaniak-Routing: alpha Precedence: bulk List-ID: Hi, Thanks for this fix. A few suggestions: On Wed, Aug 30, 2023 at 02:08:58PM +0800, Ding Xiang wrote: > The opened file should be closed before return, > otherwise resource leak will occur > > Signed-off-by: Ding Xiang > --- > tools/testing/selftests/landlock/fs_test.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c > index 83d565569512..687a66ea9799 100644 > --- a/tools/testing/selftests/landlock/fs_test.c > +++ b/tools/testing/selftests/landlock/fs_test.c > @@ -124,13 +124,17 @@ static bool supports_filesystem(const char *const filesystem) > return true; > > /* filesystem can be null for bind mounts. */ > - if (!filesystem) > + if (!filesystem) { > + fclose(inf); > return true; Can you please change these two lines (and the next hunk) with a `goto out` (and then don't add the if braces), initialize res to true when it is declared, and add the `out` label below? > + } > > len = snprintf(str, sizeof(str), "nodev\t%s\n", filesystem); > - if (len >= sizeof(str)) > + if (len >= sizeof(str)) { > + fclose(inf); > /* Ignores too-long filesystem names. */ > return true; > + } > > res = fgrep(inf, str); out: > fclose(inf); > -- > 2.38.1 > > >