]> granicus.if.org Git - python/commitdiff
Fix memory leak in os.readlink
authorNeal Norwitz <nnorwitz@gmail.com>
Sun, 12 Aug 2007 17:11:13 +0000 (17:11 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sun, 12 Aug 2007 17:11:13 +0000 (17:11 +0000)
Modules/posixmodule.c

index 8a78d8c152e506b5d63a28dbe512280f8d5406a0..24c9e15537d8164826271efce54f7cf998776224 100644 (file)
@@ -5783,7 +5783,10 @@ posix_readlink(PyObject *self, PyObject *args)
                return NULL;
 #ifdef Py_USING_UNICODE
        v = PySequence_GetItem(args, 0);
-       if (v == NULL) return NULL;
+       if (v == NULL) {
+               PyMem_Free(path);
+               return NULL;
+       }
 
        if (PyUnicode_Check(v)) {
                arg_is_unicode = 1;
@@ -5795,8 +5798,9 @@ posix_readlink(PyObject *self, PyObject *args)
        n = readlink(path, buf, (int) sizeof buf);
        Py_END_ALLOW_THREADS
        if (n < 0)
-               return posix_error_with_filename(path);
+               return posix_error_with_allocated_filename(path);
 
+       PyMem_Free(path);
        v = PyString_FromStringAndSize(buf, n);
 #ifdef Py_USING_UNICODE
        if (arg_is_unicode) {