From 92dd9e47fe8862ee38770744c165b680cb5241b1 Mon Sep 17 00:00:00 2001 From: M Bussonnier Date: Tue, 17 Dec 2024 20:39:14 +0100 Subject: [PATCH] Always free --- IPython/utils/_process_win32.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/IPython/utils/_process_win32.py b/IPython/utils/_process_win32.py index 243eccb79a..bc6428e83a 100644 --- a/IPython/utils/_process_win32.py +++ b/IPython/utils/_process_win32.py @@ -190,16 +190,18 @@ def arg_split( return py_arg_split(commandline, posix=posix, strict=strict) argvn = c_int() result_pointer = CommandLineToArgvW(commandline.lstrip(), ctypes.byref(argvn)) - result_array_type = LPCWSTR * argvn.value - result = [ - arg - for arg in result_array_type.from_address( - ctypes.addressof(result_pointer.contents) - ) - if arg is not None - ] - # for side effects - _ = LocalFree(result_pointer) + try: + result_array_type = LPCWSTR * argvn.value + result = [ + arg + for arg in result_array_type.from_address( + ctypes.addressof(result_pointer.contents) + ) + if arg is not None + ] + finally: + # for side effects + _ = LocalFree(result_pointer) return result except AttributeError: arg_split = py_arg_split