Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp213106rdf; Mon, 20 Nov 2023 23:49:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IH1y378TaHs6vd1VNUYRaQdZeNUUAUtuFA3HX74AMoLVabr/76LWh/V7rtMhEfLS8nuerw8 X-Received: by 2002:aa7:8bd8:0:b0:6b7:b42f:e438 with SMTP id s24-20020aa78bd8000000b006b7b42fe438mr7679310pfd.8.1700552950909; Mon, 20 Nov 2023 23:49:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700552950; cv=none; d=google.com; s=arc-20160816; b=gf15tbcOq3/gwIk4+GQWLDqHRXdkFVNll28vXAeDaWBzBrdE3IMsYJWPm2SrHsiGd2 V8wc8wBAAm5JvpmzPPI3EUPTC4nvvulaxrqA7hO7lIS5UtVTSx0ezz49W1BlrmOIJ+9p ii2aU1ju9VuWvQiDJ0qMFNYbATs3aZkZoaPPV49jHmOcQ8rNrazHDjieb7FPg3TYdBDk Z0AQqYSrqH49orHp8p0CwjJ+TKBLsFu7wLXNRbiFbC8EAMC9r9UF8YZPTXEKe42boMtd yhGsDslLqj9Xa/YbmciZoouIEZimvn++KQpMlNN5yhKBmQbSQYbLsb3GMh4bV7JlEcke /eyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=J1Y57R3L0HcMhbg8KOSSlooP9Ta78IZFzYPPiGoMQM8=; fh=HO6+1zTumGyn7A56oz4IKt+IY+io3ncr375AOliEQok=; b=JprQcVvWH2mMtS0+6qL25E1Hyf9yhxlaoUItQSA6FWtjRW2kUaavx1C57fkA1kGYgJ UQOjCe6Mu/C0AfLlGHgtFXEc6xV6iFtNeqnN8HS1+Di3JbV85Hw5wlNfGsDfbAVNo7dm yg1Eix/KPw6NkFv+1wEGTob1GYgSm/u0h3aAp+FhnhEBCCiKbOTEC6v60MI91jmp5Wip +hN2li303egcdNes7jkyHMzIHnIHv4qdjGWCY+TWW7fnWW0Zl46Ss1GtW1bpQnHM6FGG +6nZDK9mlVNBkr+kD28wZdn3A4B+ZA9h5j5xX9jHdGJ82XiUAKzw6WzOVgo37lXzVQKo rxCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WoEXrYmT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id bn13-20020a056a02030d00b005c1b2f29f24si10496269pgb.512.2023.11.20.23.49.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 23:49:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WoEXrYmT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 0E5F68032006; Mon, 20 Nov 2023 23:48:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229585AbjKUHr5 (ORCPT + 99 others); Tue, 21 Nov 2023 02:47:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229504AbjKUHrx (ORCPT ); Tue, 21 Nov 2023 02:47:53 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E17DA11A for ; Mon, 20 Nov 2023 23:47:49 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40891d38e3fso19967485e9.1 for ; Mon, 20 Nov 2023 23:47:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700552868; x=1701157668; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=J1Y57R3L0HcMhbg8KOSSlooP9Ta78IZFzYPPiGoMQM8=; b=WoEXrYmTOCuaf6fQP2MS3rLn0xC8In8RcUy376BoNX7OoJhhha/gq397UppnvXY0DW 8gjGzKsQvoc21JTUEL3triPQ0dt96FVsbYewRHdmR5mi/z+YEPp1aASWh2C0j497BM8T N5pDB9ag9sbyLX5Ei7niXFl7zrHjbLUn8mOq6IaY471PdhbxYScWwFLiQmSYK+CmWmiF 8PCsyhFr0t40mB2q77I3mktwROXOGCiQPnKlSpLtz6eMG8/w46vcw9oOvFwRs7+YeBJn Rol/DyzLpwGlArxk7VJ+VzjFZWsziqSUnlPuXaIsVdflpRI9T1nghlDyPBYxtznVUgfL P1jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700552868; x=1701157668; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=J1Y57R3L0HcMhbg8KOSSlooP9Ta78IZFzYPPiGoMQM8=; b=bNRiYsyKvHsvosPbR6cYpd2L2im/f62GiFvvJTTNc4w0Khi4qVr2qKRxkqRzKd/wS1 Jmd3ReKRTyihn6XE7QRWFeo+FD+UVS6uxcVpF2a0+bDdW5fuehd4qb57mVveYuHI5pDX oWl1sHl/2tLhM9vpNGXW3kRbhD3gkSz6IgJ4Em2EbyuRNMfOcaDhQYWSRl4N7bMvJ2+S t1cvzFd9RNIb4bXO/B1jKTdXA2/TE5g3r/sO3O0LmKyXiDr9+ujTqNbMpDTdi6Ah7oA7 rc3pCGoDdSYc53agDur+yy+W/ZqB8mQEuFoitCZ3otqUVVcBijF0VPYIGtdxdraxGe58 66TA== X-Gm-Message-State: AOJu0Yw3orGPejE0IIx6j5k9nD5j8/lIA3hEwWKuBJCUmI560EEZy1Ul gkjFH1hO+y0PyGkujV2AI0O3BQ== X-Received: by 2002:a05:600c:4f55:b0:402:f55c:faee with SMTP id m21-20020a05600c4f5500b00402f55cfaeemr7478517wmq.26.1700552868351; Mon, 20 Nov 2023 23:47:48 -0800 (PST) Received: from localhost ([102.36.222.112]) by smtp.gmail.com with ESMTPSA id n21-20020a7bc5d5000000b003fbe4cecc3bsm19975709wmk.16.2023.11.20.23.47.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 23:47:48 -0800 (PST) Date: Tue, 21 Nov 2023 02:47:44 -0500 From: Dan Carpenter To: zhujun2 Cc: kernel-janitors@vger.kernel.org, mathieu.desnoyers@efficios.com, ivan.orlov0322@gmail.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, shuah@kernel.org Subject: Re: [PATCH] selftests/media_tests: fix a resource leak Message-ID: <71465605-7179-4281-8ec8-80f741e78038@suswa.mountain> References: <8431b227-d053-4a9a-a278-2a43753fdaf7@efficios.com> <20231121025918.2570-1-zhujun2@cmss.chinamobile.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231121025918.2570-1-zhujun2@cmss.chinamobile.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 20 Nov 2023 23:48:12 -0800 (PST) On Mon, Nov 20, 2023 at 06:59:18PM -0800, zhujun2 wrote: > 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); Open failed so there is nothing to close. > exit(-1); When we exit() then all the resources are automatically reclaimed by the operating system so we really don't worry about leaks at all in short running programs. It's different for an operating system or a web server which is expected to have a long uptime. But these programs are going to run quickly and then exit so resource leaks are not an issue. regards, dan carpenter