Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp118162rdf; Mon, 20 Nov 2023 18:59:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IHxxd1FjLZObgG6G/X0mVCVhRefeSo64CBsUIQBIACQ5mbTu1yQreJxVWMaaA7SzjiyK3B+ X-Received: by 2002:a05:6870:3d92:b0:1f9:67e4:26c2 with SMTP id lm18-20020a0568703d9200b001f967e426c2mr1201386oab.53.1700535581213; Mon, 20 Nov 2023 18:59:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700535581; cv=none; d=google.com; s=arc-20160816; b=O8mAQzz9t5b99N51pbIB8ImwAif4THqUndt+SvqEyTQzZJiNZteqerX72tToceOly9 IKGmAgegYSHqBarYMFgf4BPAzEa0qWrJKQXY8c4t+gZKkSs1zxW+kdWa40r4loAIaHdO vIEpJFqwITM21YwSqpLH7TmDDcu6x95LQo2mv+2FEpORVISBZOrUYVW3m0CYjTqOeHla EWfAncEfXRrjmfAm6pwwlAecXR83Z5sMaxSnadyFyBZVwuruHO/H8MP2N6igW1aThVpJ zI5xamo+EQ6ItKXXoHON1UYa8fBg1zz8kquZF/B43kzTfFfFCHLtQolipGdRgw4Zg0lk jMhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=C/7e7S1fpi2dKGrsMbleFx8RSgASGcEQy9W71EN7MUM=; fh=PZCTtQ6PHJQHBTMvOMilMFVyz2sXeUhpDgWnJ8it6vw=; b=tn9DB11Tv7N+7qJgRMsSxRtrqjvxZN6mMVIA6PcvzTSvfRaBdQKbVsyizw/TY1TtW2 CMBs26GP9uWs0xGMS5uBfqVtCX2cpLPOeKDWhArBhObsytk9yolPkha4MddeGSKjtBrI QM/tLCiuJcKLL500E4LboXKxhon1J8YFxno49/uC1IPbCnRvK8Ct1Z4o0zJ2PyymXAZS UKHa/Mj1x5Yq3Ss/e12XIf2fy2aa58WgdbejPMj0B1BvOsflAT+PNMS+xmwNW/zWx3ub QRJeSU8L4TNUr3s5Zyi+R9gU7Q3LXwKvE83COAvmrvUyaFrsJ7hrZ5TeOZnChO0PTPXk F3hw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id s66-20020a635e45000000b005b11e5a69fdsi9658767pgb.508.2023.11.20.18.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 18:59:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 0F770802F548; Mon, 20 Nov 2023 18:59:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232876AbjKUC7c (ORCPT + 99 others); Mon, 20 Nov 2023 21:59:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229539AbjKUC7b (ORCPT ); Mon, 20 Nov 2023 21:59:31 -0500 Received: from cmccmta1.chinamobile.com (cmccmta8.chinamobile.com [111.22.67.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D8553DC; Mon, 20 Nov 2023 18:59:24 -0800 (PST) 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-app02-12002 (RichMail) with SMTP id 2ee2655c1d09f85-7c2b4; Tue, 21 Nov 2023 10:59:21 +0800 (CST) X-RM-TRANSID: 2ee2655c1d09f85-7c2b4 X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from ubuntu.localdomain (unknown[10.54.5.255]) by rmsmtp-syy-appsvr07-12007 (RichMail) with SMTP id 2ee7655c1d082ed-c5454; Tue, 21 Nov 2023 10:59:21 +0800 (CST) X-RM-TRANSID: 2ee7655c1d082ed-c5454 From: zhujun2 To: kernel-janitors@vger.kernel.org Cc: mathieu.desnoyers@efficios.com, ivan.orlov0322@gmail.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, shuah@kernel.org, zhujun2@cmss.chinamobile.com Subject: [PATCH] selftests/media_tests: fix a resource leak Date: Mon, 20 Nov 2023 18:59:18 -0800 Message-Id: <20231121025918.2570-1-zhujun2@cmss.chinamobile.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <8431b227-d053-4a9a-a278-2a43753fdaf7@efficios.com> References: <8431b227-d053-4a9a-a278-2a43753fdaf7@efficios.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 20 Nov 2023 18:59:39 -0800 (PST) The opened file should be closed in main(), otherwise resource leak will occur that this problem was discovered by code reading Signed-off-by: zhujun2 --- tools/testing/selftests/media_tests/media_device_open.c | 3 +++ tools/testing/selftests/media_tests/media_device_test.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tools/testing/selftests/media_tests/media_device_open.c b/tools/testing/selftests/media_tests/media_device_open.c index 93183a37b133..2dfb2a11b148 100644 --- a/tools/testing/selftests/media_tests/media_device_open.c +++ b/tools/testing/selftests/media_tests/media_device_open.c @@ -70,6 +70,7 @@ int main(int argc, char **argv) fd = open(media_device, O_RDWR); if (fd == -1) { printf("Media Device open errno %s\n", strerror(errno)); + close(fd); exit(-1); } @@ -79,4 +80,6 @@ int main(int argc, char **argv) else printf("Media device model %s driver %s\n", mdi.model, mdi.driver); + + close(fd); } diff --git a/tools/testing/selftests/media_tests/media_device_test.c b/tools/testing/selftests/media_tests/media_device_test.c index 4b9953359e40..7cabb62535a7 100644 --- a/tools/testing/selftests/media_tests/media_device_test.c +++ b/tools/testing/selftests/media_tests/media_device_test.c @@ -79,6 +79,7 @@ int main(int argc, char **argv) fd = open(media_device, O_RDWR); if (fd == -1) { printf("Media Device open errno %s\n", strerror(errno)); + close(fd); exit(-1); } @@ -100,4 +101,6 @@ int main(int argc, char **argv) sleep(10); count--; } + + close(fd); } -- 2.17.1