From patchwork Wed Jun 15 09:36:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ding Xiang X-Patchwork-Id: 12881983 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 D80ACCCA473 for ; Wed, 15 Jun 2022 09:40:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237420AbiFOJkO (ORCPT ); Wed, 15 Jun 2022 05:40:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244365AbiFOJjz (ORCPT ); Wed, 15 Jun 2022 05:39:55 -0400 X-Greylist: delayed 184 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 15 Jun 2022 02:39:37 PDT Received: from cmccmta3.chinamobile.com (cmccmta3.chinamobile.com [221.176.66.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0CBFA3DDF8 for ; Wed, 15 Jun 2022 02:39:36 -0700 (PDT) X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from spf.mail.chinamobile.com (unknown[172.16.121.87]) by rmmx-syy-dmz-app11-12011 (RichMail) with SMTP id 2eeb62a9a81b5ec-42973; Wed, 15 Jun 2022 17:36:30 +0800 (CST) X-RM-TRANSID: 2eeb62a9a81b5ec-42973 X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from localhost.localdomain (unknown[223.108.79.97]) by rmsmtp-syy-appsvrnew04-12029 (RichMail) with SMTP id 2efd62a9a81d15b-c5d4a; Wed, 15 Jun 2022 17:36:30 +0800 (CST) X-RM-TRANSID: 2efd62a9a81d15b-c5d4a From: Ding Xiang To: akpm@linux-foundation.org, shuah@kernel.org Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] selftests: vm: Fix resource leak when return error Date: Wed, 15 Jun 2022 17:36:29 +0800 Message-Id: <20220615093629.1330809-1-dingxiang@cmss.chinamobile.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org When return on an error path, file handle need to be closed to prevent resource leak Signed-off-by: Ding Xiang Reviewed-by: Shuah Khan --- tools/testing/selftests/vm/ksm_tests.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/vm/ksm_tests.c b/tools/testing/selftests/vm/ksm_tests.c index 2fcf24312da8..f5e4e0bbd081 100644 --- a/tools/testing/selftests/vm/ksm_tests.c +++ b/tools/testing/selftests/vm/ksm_tests.c @@ -54,6 +54,7 @@ static int ksm_write_sysfs(const char *file_path, unsigned long val) } if (fprintf(f, "%lu", val) < 0) { perror("fprintf"); + fclose(f); return 1; } fclose(f); @@ -72,6 +73,7 @@ static int ksm_read_sysfs(const char *file_path, unsigned long *val) } if (fscanf(f, "%lu", val) != 1) { perror("fscanf"); + fclose(f); return 1; } fclose(f);