mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #15895: Fix FILE pointer leak in PyRun_SimpleFileExFlags() when filename points to a pyc/pyo file and closeit is false.
This commit is contained in:
parent
26b9f4b2f3
commit
6a77af690f
2 changed files with 8 additions and 1 deletions
|
@ -10,6 +10,9 @@ What's New in Python 3.3.1
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #15895: Fix FILE pointer leak in PyRun_SimpleFileExFlags() when
|
||||||
|
filename points to a pyc/pyo file and closeit is false.
|
||||||
|
|
||||||
- Issue #15900: Fix reference leak in PyUnicode_TranslateCharmap().
|
- Issue #15900: Fix reference leak in PyUnicode_TranslateCharmap().
|
||||||
|
|
||||||
- Issue #15839: Convert SystemErrors in super() to RuntimeErrors.
|
- Issue #15839: Convert SystemErrors in super() to RuntimeErrors.
|
||||||
|
|
|
@ -1385,7 +1385,7 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
|
||||||
{
|
{
|
||||||
PyObject *m, *d, *v;
|
PyObject *m, *d, *v;
|
||||||
const char *ext;
|
const char *ext;
|
||||||
int set_file_name = 0, ret;
|
int set_file_name = 0, close_own_fp = 0, ret;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
m = PyImport_AddModule("__main__");
|
m = PyImport_AddModule("__main__");
|
||||||
|
@ -1419,6 +1419,7 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
close_own_fp = 1;
|
||||||
/* Turn on optimization if a .pyo file is given */
|
/* Turn on optimization if a .pyo file is given */
|
||||||
if (strcmp(ext, ".pyo") == 0)
|
if (strcmp(ext, ".pyo") == 0)
|
||||||
Py_OptimizeFlag = 1;
|
Py_OptimizeFlag = 1;
|
||||||
|
@ -1449,6 +1450,9 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
done:
|
done:
|
||||||
|
if (close_own_fp) {
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
if (set_file_name && PyDict_DelItemString(d, "__file__"))
|
if (set_file_name && PyDict_DelItemString(d, "__file__"))
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue