Skip to content

Commit 73d767b

Browse files
JelleZijlstraStanFromIreland
authored andcommitted
[3.13] gh-145376: Fix various reference leaks (GH-145377)
(cherry picked from commit bd13cc0) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent 53e0725 commit 73d767b

4 files changed

Lines changed: 4 additions & 1 deletion

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix reference leaks in various unusual error scenarios.

Modules/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ pymain_run_interactive_hook(int *exitcode)
511511
}
512512

513513
if (PySys_Audit("cpython.run_interactivehook", "O", hook) < 0) {
514+
Py_DECREF(hook);
514515
goto error;
515516
}
516517

Python/pythonrun.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,7 @@ _PyErr_Display(PyObject *file, PyObject *unused, PyObject *value, PyObject *tb)
11501150

11511151
if (print_exception_fn == NULL || !PyCallable_Check(print_exception_fn)) {
11521152
Py_DECREF(traceback_module);
1153+
Py_XDECREF(print_exception_fn);
11531154
goto fallback;
11541155
}
11551156

Python/sysmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1782,7 +1782,7 @@ sys_getwindowsversion_impl(PyObject *module)
17821782
PyObject *realVersion = _sys_getwindowsversion_from_kernel32();
17831783
if (!realVersion) {
17841784
if (!PyErr_ExceptionMatches(PyExc_WindowsError)) {
1785-
return NULL;
1785+
goto error;
17861786
}
17871787

17881788
PyErr_Clear();

0 commit comments

Comments
 (0)