# HG changeset patch # User Augie Fackler # Date 2015-01-27 15:17:16 # Node ID 2d2c0a8eeeb8764daa94400e7de16a02971361a9 # Parent 6156edaa82aab1193875f8ccd9c2cbe5661996b9 osutil: fix memory leak of PyBytes of path in statfiles Spotted with cpychecker. diff --git a/mercurial/osutil.c b/mercurial/osutil.c --- a/mercurial/osutil.c +++ b/mercurial/osutil.c @@ -410,17 +410,22 @@ static PyObject *statfiles(PyObject *sel return NULL; for (i = 0; i < count; i++) { - PyObject *stat; + PyObject *stat, *pypath; struct stat st; int ret, kind; char *path; - path = PyString_AsString(PySequence_GetItem(names, i)); + pypath = PySequence_GetItem(names, i); + if (!pypath) + return NULL; + path = PyString_AsString(pypath); if (path == NULL) { + Py_DECREF(pypath); PyErr_SetString(PyExc_TypeError, "not a string"); goto bail; } ret = lstat(path, &st); + Py_DECREF(pypath); kind = st.st_mode & S_IFMT; if (ret != -1 && (kind == S_IFREG || kind == S_IFLNK)) { stat = makestat(&st);