Re: [PATCH] scripts/spdxcheck: fix file descriptor leak in read_spdxdata()

From: Jonathan Corbet

Date: Wed Aug 26 2026 - 12:56:18 EST


3237174131@xxxxxx writes:

> Hi all,
>
> This is my first kernel patch. Please let me know if anything is wrong.

Sending the patch as an attachment and the lack of a useful changelog
are both problems; please see
Documentation/process/submitting-patches.rst for information on how to
do this properly.

But, beyond that:

> Signed-off-by: Xia Zhoxin <3237174131@xxxxxx>
> From: Xia Zhoxin <3237174131@xxxxxx>
> Subject: [PATCH] scripts/spdxcheck: fix file descriptor leak in read_spdxdata()
> To: linux-kernel@xxxxxxxxxxxxxxx
> Cc: tglx@xxxxxxxxxx, gregkh@xxxxxxxxxxxxxxxxxxx
>
> Hi all,
>
> This is my first kernel patch. Please let me know if anything is wrong.
>
> Signed-off-by: Xia Zhoxin <3237174131@xxxxxx>
> ---
> scripts/spdxcheck.py | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/spdxcheck.py b/scripts/spdxcheck.py
> --- a/scripts/spdxcheck.py
> +++ b/scripts/spdxcheck.py
> @@ -72,7 +72,8 @@ def read_spdxdata(repo):
> exception = None
> - for l in open(el.path, encoding="utf-8").readlines():
> + with open(el.path, encoding="utf-8") as f:
> + for l in f:
> if l.startswith('Valid-License-Identifier:'):

open() returns a file object (*not* a file descriptor) that will
immediately go to a reference count of zero once .readlines() completes.
Garbage collection will then clean it up. So there is no actual leak
here.

Thanks,

jon