osutil: fix memory leak of PyBytes of path in statfiles stable
authorAugie Fackler <augie@google.com>
Tue, 27 Jan 2015 10:17:16 -0500
branchstable
changeset 23966 2d2c0a8eeeb8
parent 23965 6156edaa82aa
child 23967 448bb32b8ee6
osutil: fix memory leak of PyBytes of path in statfiles Spotted with cpychecker.
mercurial/osutil.c
--- 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);