From 8b5ac23efdc18fdc3e4b8199d216b8fc4d77eed3 Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 8 Mar 2026 20:17:28 +0000 Subject: [PATCH] fix au_unpk fd-leak (e.g. failed epub thumbing) --- copyparty/mtag.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/copyparty/mtag.py b/copyparty/mtag.py index c08d253c..1d4df60e 100644 --- a/copyparty/mtag.py +++ b/copyparty/mtag.py @@ -133,6 +133,7 @@ class MParser(object): def au_unpk( log: "NamedLogger", fmt_map: dict[str, str], abspath: str, vn: Optional[VFS] = None ) -> str: + fd = 0 ret = "" maxsz = 1024 * 1024 * 64 try: @@ -186,6 +187,7 @@ def au_unpk( fsz = 0 with os.fdopen(fd, "wb") as fo: + fd = 0 while True: buf = fi.read(32768) if not buf: @@ -200,6 +202,8 @@ def au_unpk( return ret except Exception as ex: + if fd: + os.close(fd) if ret: t = "failed to decompress file %r: %r" log(t % (abspath, ex))