mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
[3.14] gh-142776: Ensure fp file descriptor is closed on all code paths in import.c (GH-142777) (#142988)
gh-142776: Ensure fp file descriptor is closed on all code paths in import.c (GH-142777)
(cherry picked from commit 6a4f10325d)
This commit is contained in:
parent
dbc7fd61d8
commit
dcbde6b792
2 changed files with 4 additions and 8 deletions
|
|
@ -0,0 +1 @@
|
|||
Fix a file descriptor leak in import.c
|
||||
|
|
@ -4687,6 +4687,7 @@ static PyObject *
|
|||
_imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file)
|
||||
/*[clinic end generated code: output=83249b827a4fde77 input=c31b954f4cf4e09d]*/
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
PyObject *mod = NULL;
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
|
||||
|
|
@ -4729,16 +4730,12 @@ _imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file)
|
|||
/* We would move this (and the fclose() below) into
|
||||
* _PyImport_GetModInitFunc(), but it isn't clear if the intervening
|
||||
* code relies on fp still being open. */
|
||||
FILE *fp;
|
||||
if (file != NULL) {
|
||||
fp = Py_fopen(info.filename, "r");
|
||||
if (fp == NULL) {
|
||||
goto finally;
|
||||
}
|
||||
}
|
||||
else {
|
||||
fp = NULL;
|
||||
}
|
||||
|
||||
PyModInitFunction p0 = _PyImport_GetModInitFunc(&info, fp);
|
||||
if (p0 == NULL) {
|
||||
|
|
@ -4762,12 +4759,10 @@ _imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file)
|
|||
}
|
||||
#endif
|
||||
|
||||
// XXX Shouldn't this happen in the error cases too (i.e. in "finally")?
|
||||
if (fp) {
|
||||
finally:
|
||||
if (fp != NULL) {
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
finally:
|
||||
_Py_ext_module_loader_info_clear(&info);
|
||||
return mod;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue