mirror of
https://github.com/python/cpython.git
synced 2025-11-26 13:22:51 +00:00
Plug a few memory leaks in utime(). path is allocated from within
PyArg_ParseTuple() since the format is "et" This change should be reviewed carefully. Bugfix candidate.
This commit is contained in:
parent
c28e7ad3d0
commit
9665271f92
1 changed files with 12 additions and 4 deletions
|
|
@ -2049,15 +2049,20 @@ posix_utime(PyObject *self, PyObject *args)
|
||||||
else if (!PyTuple_Check(arg) || PyTuple_Size(arg) != 2) {
|
else if (!PyTuple_Check(arg) || PyTuple_Size(arg) != 2) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"utime() arg 2 must be a tuple (atime, mtime)");
|
"utime() arg 2 must be a tuple (atime, mtime)");
|
||||||
|
PyMem_Free(path);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (extract_time(PyTuple_GET_ITEM(arg, 0),
|
if (extract_time(PyTuple_GET_ITEM(arg, 0),
|
||||||
&atime, &ausec) == -1)
|
&atime, &ausec) == -1) {
|
||||||
|
PyMem_Free(path);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
if (extract_time(PyTuple_GET_ITEM(arg, 1),
|
if (extract_time(PyTuple_GET_ITEM(arg, 1),
|
||||||
&mtime, &musec) == -1)
|
&mtime, &musec) == -1) {
|
||||||
|
PyMem_Free(path);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
ATIME = atime;
|
ATIME = atime;
|
||||||
MTIME = mtime;
|
MTIME = mtime;
|
||||||
#ifdef HAVE_UTIMES
|
#ifdef HAVE_UTIMES
|
||||||
|
|
@ -2082,11 +2087,14 @@ posix_utime(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
#ifdef Py_WIN_WIDE_FILENAMES
|
#ifdef Py_WIN_WIDE_FILENAMES
|
||||||
if (have_unicode_filename)
|
if (have_unicode_filename) {
|
||||||
|
PyMem_Free(path);
|
||||||
return posix_error_with_unicode_filename(wpath);
|
return posix_error_with_unicode_filename(wpath);
|
||||||
|
}
|
||||||
#endif /* Py_WIN_WIDE_FILENAMES */
|
#endif /* Py_WIN_WIDE_FILENAMES */
|
||||||
return posix_error_with_filename(path);
|
return posix_error_with_allocated_filename(path);
|
||||||
}
|
}
|
||||||
|
PyMem_Free(path);
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
#undef UTIME_ARG
|
#undef UTIME_ARG
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue