From patchwork Wed Aug 30 06:08:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ding Xiang X-Patchwork-Id: 13369969 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 322D4C83F18 for ; Wed, 30 Aug 2023 06:13:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238336AbjH3GMh (ORCPT ); Wed, 30 Aug 2023 02:12:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240021AbjH3GMS (ORCPT ); Wed, 30 Aug 2023 02:12:18 -0400 X-Greylist: delayed 187 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 29 Aug 2023 23:12:12 PDT Received: from cmccmta2.chinamobile.com (cmccmta8.chinamobile.com [111.22.67.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E1EBBCCB; Tue, 29 Aug 2023 23:12:12 -0700 (PDT) X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from spf.mail.chinamobile.com (unknown[10.188.0.87]) by rmmx-syy-dmz-app06-12006 (RichMail) with SMTP id 2ee664eedcfb838-f1cb1; Wed, 30 Aug 2023 14:08:59 +0800 (CST) X-RM-TRANSID: 2ee664eedcfb838-f1cb1 X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from localhost.localdomain.localdomain (unknown[10.54.5.255]) by rmsmtp-syy-appsvr10-12010 (RichMail) with SMTP id 2eea64eedcfad0a-0607d; Wed, 30 Aug 2023 14:08:59 +0800 (CST) X-RM-TRANSID: 2eea64eedcfad0a-0607d From: Ding Xiang To: shuah@kernel.org, mic@digikod.net Cc: linux-security-module@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] selftests/landlock: Fix a resource leak Date: Wed, 30 Aug 2023 14:08:58 +0800 Message-Id: <20230830060858.2841-1-dingxiang@cmss.chinamobile.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org 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; + } 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); fclose(inf);