mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
plugged leak noted by nnorwitz: the 'et' format returns allocated memory
This commit is contained in:
parent
a2eaf31727
commit
2fe07fda2d
1 changed files with 4 additions and 2 deletions
|
|
@ -1771,7 +1771,7 @@ posix_listdir(PyObject *self, PyObject *args)
|
||||||
return d;
|
return d;
|
||||||
#else
|
#else
|
||||||
|
|
||||||
char *name;
|
char *name = NULL;
|
||||||
PyObject *d, *v;
|
PyObject *d, *v;
|
||||||
DIR *dirp;
|
DIR *dirp;
|
||||||
struct dirent *ep;
|
struct dirent *ep;
|
||||||
|
|
@ -1784,10 +1784,11 @@ posix_listdir(PyObject *self, PyObject *args)
|
||||||
if (!PyArg_ParseTuple(args, "et:listdir", Py_FileSystemDefaultEncoding, &name))
|
if (!PyArg_ParseTuple(args, "et:listdir", Py_FileSystemDefaultEncoding, &name))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((dirp = opendir(name)) == NULL) {
|
if ((dirp = opendir(name)) == NULL) {
|
||||||
return posix_error_with_filename(name);
|
return posix_error_with_allocated_filename(name);
|
||||||
}
|
}
|
||||||
if ((d = PyList_New(0)) == NULL) {
|
if ((d = PyList_New(0)) == NULL) {
|
||||||
closedir(dirp);
|
closedir(dirp);
|
||||||
|
PyMem_Free(name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
while ((ep = readdir(dirp)) != NULL) {
|
while ((ep = readdir(dirp)) != NULL) {
|
||||||
|
|
@ -1826,6 +1827,7 @@ posix_listdir(PyObject *self, PyObject *args)
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
}
|
}
|
||||||
closedir(dirp);
|
closedir(dirp);
|
||||||
|
PyMem_Free(name);
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue