mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
* Fix a refleak when a preexec_fn was supplied (preexec_fn_args_tuple was not
being defref'ed). * Fixes another potential refleak of a reference to the gc module in the unlikely odd case where gc module isenabled or disable calls fail. * Adds a unittest for the above case to verify behavior and lack of leaks.
This commit is contained in:
parent
3f88c0ece6
commit
32ec9da166
2 changed files with 53 additions and 3 deletions
|
@ -204,15 +204,21 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
|
|||
if (gc_module == NULL)
|
||||
return NULL;
|
||||
result = PyObject_CallMethod(gc_module, "isenabled", NULL);
|
||||
if (result == NULL)
|
||||
if (result == NULL) {
|
||||
Py_DECREF(gc_module);
|
||||
return NULL;
|
||||
}
|
||||
need_to_reenable_gc = PyObject_IsTrue(result);
|
||||
Py_DECREF(result);
|
||||
if (need_to_reenable_gc == -1)
|
||||
if (need_to_reenable_gc == -1) {
|
||||
Py_DECREF(gc_module);
|
||||
return NULL;
|
||||
}
|
||||
result = PyObject_CallMethod(gc_module, "disable", NULL);
|
||||
if (result == NULL)
|
||||
if (result == NULL) {
|
||||
Py_DECREF(gc_module);
|
||||
return NULL;
|
||||
}
|
||||
Py_DECREF(result);
|
||||
}
|
||||
|
||||
|
@ -307,6 +313,7 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
|
|||
Py_XDECREF(gc_module);
|
||||
return NULL;
|
||||
}
|
||||
Py_XDECREF(preexec_fn_args_tuple);
|
||||
Py_XDECREF(gc_module);
|
||||
|
||||
if (pid == -1)
|
||||
|
@ -322,6 +329,7 @@ cleanup:
|
|||
_Py_FreeCharPArray(exec_array);
|
||||
Py_XDECREF(converted_args);
|
||||
Py_XDECREF(fast_args);
|
||||
Py_XDECREF(preexec_fn_args_tuple);
|
||||
|
||||
/* Reenable gc if it was disabled. */
|
||||
if (need_to_reenable_gc)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue