[issue2222] Memory leak in os.rename?

Alexander Belopolsky report at bugs.python.org
Mon Mar 3 16:16:52 CET 2008


Alexander Belopolsky added the comment:

It looks like non-windows code has a similar problem:

static PyObject * 
posix_2str(PyObject *args, 
           char *format, 
           int (*func)(const char *, const char *)) 
{ 
        char *path1 = NULL, *path2 = NULL; 
        int res; 
        if (!PyArg_ParseTuple(args, format, 
                              Py_FileSystemDefaultEncoding, &path1, 
                              Py_FileSystemDefaultEncoding, &path2)) 
                return NULL; 

If decoding of path2 fails, path1 is never freed.

On the patch itself, arguably  Py_XDECREF(o2) is not necessary, but 
leaving it in is probably good defensive programming (e.g. if more args 
are added in the future.)  I am +1 on the patch as is.

Please add a unit test that exercises the new code.  Check that the leak 
is detected when the unit test is ran with gc.set_debug(gc.DEBUG_LEAK).

----------
nosy: +belopolsky

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2222>
__________________________________


More information about the Python-bugs-list mailing list