Skip to content

Commit cd91bd1

Browse files
committed
Prevent leaking of handle in _check_pid_win32
credit to @garu57 fixes #4862
1 parent 2b47644 commit cd91bd1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

notebook/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,15 @@ def check_version(v, check):
284284
return True
285285

286286

287-
# Copy of IPython.utils.process.check_pid:
288-
289287
def _check_pid_win32(pid):
290288
import ctypes
291289
# OpenProcess returns 0 if no such process (of ours) exists
292290
# positive int otherwise
293-
return bool(ctypes.windll.kernel32.OpenProcess(1,0,pid))
291+
handle = ctypes.windll.kernel32.OpenProcess(1,0,pid)
292+
if handle:
293+
# the handle must be closed or the kernel process object won't be freed
294+
ctypes.windll.kernel32.CloseHandle( handle )
295+
return bool(handle)
294296

295297
def _check_pid_posix(pid):
296298
"""Copy of IPython.utils.process.check_pid"""

0 commit comments

Comments
 (0)