From 01ce0e1d1a1984ddb25cd5f12939de81442076ff Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 16 Jul 2021 08:46:04 +0530 Subject: [PATCH] Prevent fd leak if copystat fails --- kitty/shell_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kitty/shell_integration.py b/kitty/shell_integration.py index 49850c031..dc96f499d 100644 --- a/kitty/shell_integration.py +++ b/kitty/shell_integration.py @@ -24,8 +24,8 @@ posix_template = ''' def atomic_write(path: str, data: Union[str, bytes]) -> None: mode = 'w' + ('b' if isinstance(data, bytes) else '') fd, tpath = mkstemp(dir=os.path.dirname(path), text=isinstance(data, str)) - shutil.copystat(path, tpath) with open(fd, mode) as f: + shutil.copystat(path, tpath) f.write(data) os.rename(tpath, path)