Skip to content
Myr

Merge pull request #1136 from segevfiner/winconsole-memory-leak

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix a memory leak and missing error check in _get_windows_argv

authored by David Lord · committed by GitHub · parents 17cc8d7, f957fba · Browse files · 2 files+13 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+13 added−2 removed

  • other:+13 added−2 removed

2 files+13 added−2 removed

modified:click/_winconsole.py+11 added-2 removed
15 unmodified lines
16import ctypes17import msvcrt18from ._compat import _NonClosingTextIOWrapper, text_type, PY219from ctypes import byref, POINTER, c_int, c_char, c_char_p, \20 c_void_p, py_object, c_ssize_t, c_ulong, windll, WINFUNCTYPE20 c_void_p, py_object, c_ssize_t, c_ulong, windll, WINFUNCTYPE, \21 WinError22try:23 from ctypes import pythonapi24 PyObject_GetBuffer = pythonapi.PyObject_GetBuffer25 PyBuffer_Release = pythonapi.PyBuffer_Release
14 unmodified lines
40 ('GetCommandLineW', windll.kernel32))41CommandLineToArgvW = WINFUNCTYPE(42 POINTER(LPWSTR), LPCWSTR, POINTER(c_int))(43 ('CommandLineToArgvW', windll.shell32))44LocalFree = WINFUNCTYPE(ctypes.c_void_p, ctypes.c_void_p)(45 ('LocalFree', windll.kernel32))464748STDIN_HANDLE = GetStdHandle(-10)49STDOUT_HANDLE = GetStdHandle(-11)
218 unmodified lines
268269 def _get_windows_argv():270 argc = c_int(0)271 argv_unicode = CommandLineToArgvW(GetCommandLineW(), byref(argc))272 if not argv_unicode:273 raise WinError()274 try:269 argv = [argv_unicode[i] for i in range(0, argc.value)]275 argv = [argv_unicode[i] for i in range(0, argc.value)]276 finally:277 LocalFree(argv_unicode)278 del argv_unicode279280 if not hasattr(sys, 'frozen'):281 argv = argv[1:]282 while len(argv) > 0:
48 unmodified lines
modified:CHANGES.rst+2 added
16 unmodified lines
17- Fix output on Windows Python 2.7 built with MSVC 14. :pr:`1342`18- Fix ``OSError`` when running in MSYS2. :issue:`1338`19- Fix ``OSError`` when redirecting to ``NUL`` stream on Windows.20 :issue:`1065`21- Fix memory leak when parsing Unicode arguments on Windows.22 :issue:`1136`23- Fix error in new AppEngine environments. :issue:`1462`24- Always return one of the passed choices for ``click.Choice``25 :issue:`1277`, :pr:`1318`26- Add ``no_args_is_help`` option to ``click.Command``, defaults to
575 unmodified lines