Skip to content

Commit 6d9221c

Browse files
[3.14] gh-145376: Fix various reference leaks (GH-145377) (GH-145712)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent 05b074c commit 6d9221c

File tree

5 files changed

+5
-1
lines changed

5 files changed

+5
-1
lines changed
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
@@ -509,6 +509,7 @@ pymain_run_interactive_hook(int *exitcode)
509509
}
510510

511511
if (PySys_Audit("cpython.run_interactivehook", "O", hook) < 0) {
512+
Py_DECREF(hook);
512513
goto error;
513514
}
514515

Python/crossinterp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ check_missing___main___attr(PyObject *exc)
609609
// Get the error message.
610610
PyObject *args = PyException_GetArgs(exc);
611611
if (args == NULL || args == Py_None || PyObject_Size(args) < 1) {
612+
Py_XDECREF(args);
612613
assert(!PyErr_Occurred());
613614
return 0;
614615
}

Python/pythonrun.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,7 @@ _PyErr_Display(PyObject *file, PyObject *unused, PyObject *value, PyObject *tb)
11511151
"traceback",
11521152
"_print_exception_bltin");
11531153
if (print_exception_fn == NULL || !PyCallable_Check(print_exception_fn)) {
1154+
Py_XDECREF(print_exception_fn);
11541155
goto fallback;
11551156
}
11561157

Python/sysmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,7 @@ sys_getwindowsversion_impl(PyObject *module)
17591759
PyObject *realVersion = _sys_getwindowsversion_from_kernel32();
17601760
if (!realVersion) {
17611761
if (!PyErr_ExceptionMatches(PyExc_WindowsError)) {
1762-
return NULL;
1762+
goto error;
17631763
}
17641764

17651765
PyErr_Clear();

0 commit comments

Comments
 (0)