]> granicus.if.org Git - python/commitdiff
plugged leak noted by nnorwitz: the 'et' format returns allocated memory
authorJust van Rossum <just@letterror.com>
Mon, 3 Mar 2003 19:07:13 +0000 (19:07 +0000)
committerJust van Rossum <just@letterror.com>
Mon, 3 Mar 2003 19:07:13 +0000 (19:07 +0000)
Modules/posixmodule.c

index d9033f6c5ae501e0d66f399357f492557eb20b56..cc922725d7fa08a35282bec0721fd830e516f579 100644 (file)
@@ -1771,7 +1771,7 @@ posix_listdir(PyObject *self, PyObject *args)
     return d;
 #else
 
-       char *name;
+       char *name = NULL;
        PyObject *d, *v;
        DIR *dirp;
        struct dirent *ep;
@@ -1784,10 +1784,11 @@ posix_listdir(PyObject *self, PyObject *args)
        if (!PyArg_ParseTuple(args, "et:listdir", Py_FileSystemDefaultEncoding, &name))
                return 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) {
                closedir(dirp);
+               PyMem_Free(name);
                return NULL;
        }
        while ((ep = readdir(dirp)) != NULL) {
@@ -1826,6 +1827,7 @@ posix_listdir(PyObject *self, PyObject *args)
                Py_DECREF(v);
        }
        closedir(dirp);
+       PyMem_Free(name);
 
        return d;