Skip to content

Commit c29f2ca

Browse files
committed
gh-145376: Fix various reference leaks
1 parent a1ec746 commit c29f2ca

File tree

6 files changed

+6
-1
lines changed

6 files changed

+6
-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
@@ -506,6 +506,7 @@ pymain_run_interactive_hook(int *exitcode)
506506
}
507507

508508
if (PySys_Audit("cpython.run_interactivehook", "O", hook) < 0) {
509+
Py_DECREF(hook);
509510
goto error;
510511
}
511512

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/import.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5638,6 +5638,7 @@ _imp__set_lazy_attributes_impl(PyObject *module, PyObject *modobj,
56385638

56395639
module_dict = get_mod_dict(modobj);
56405640
if (module_dict == NULL || !PyDict_CheckExact(module_dict)) {
5641+
Py_DECREF(lazy_submodules);
56415642
goto done;
56425643
}
56435644

Python/pythonrun.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ _PyErr_Display(PyObject *file, PyObject *unused, PyObject *value, PyObject *tb)
11451145
"traceback",
11461146
"_print_exception_bltin");
11471147
if (print_exception_fn == NULL || !PyCallable_Check(print_exception_fn)) {
1148+
Py_XDECREF(print_exception_fn);
11481149
goto fallback;
11491150
}
11501151

Python/sysmodule.c

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

17681768
PyErr_Clear();

0 commit comments

Comments
 (0)