osutil: fix memory leak of PyBytes of path in statfiles
Spotted with cpychecker.
--- a/mercurial/osutil.c Tue Jan 27 19:52:26 2015 -0800
+++ b/mercurial/osutil.c Tue Jan 27 10:17:16 2015 -0500
@@ -410,17 +410,22 @@
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);