From d56d8d43ee4f874d8513e40734e541c09934d5ef Mon Sep 17 00:00:00 2001 From: Siteshwar Vashisht Date: Mon, 31 Aug 2026 10:18:07 +0200 Subject: [PATCH] ukify: fix cleaning up a temporary file (#43544) Current code does not hold a reference to object returned from `tempfile.NamedTemporaryFile()`. This would cause the object to be immediately garbage collected and the temporary file is deleted. A new file is created with `linux.write_bytes()` which never gets cleaned up. Keeping a reference to this object would automatically clean up the temporary file when `make_uki()` function returns. --- src/ukify/ukify.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ukify/ukify.py b/src/ukify/ukify.py index ab5e29706c..9bfa1ecb78 100755 --- a/src/ukify/ukify.py +++ b/src/ukify/ukify.py @@ -1369,8 +1369,10 @@ def make_uki(opts: UkifyConfig) -> None: print(f'{linux} is not a valid PE file and cannot be decompressed either', file=sys.stderr) else: print(f'{linux} is compressed and cannot be loaded by UEFI, decompressing', file=sys.stderr) - linux = Path(tempfile.NamedTemporaryFile(prefix='linux-decompressed').name) - linux.write_bytes(decompressed) + linux_decompressed = tempfile.NamedTemporaryFile(prefix='linux-decompressed') + linux_decompressed.write(decompressed) + linux_decompressed.flush() + linux = Path(linux_decompressed.name) if linux and sign_args_present: assert opts.signtool is not None