changeset 23966:2d2c0a8eeeb8 stable

osutil: fix memory leak of PyBytes of path in statfiles Spotted with cpychecker.
author Augie Fackler <augie@google.com>
date Tue, 27 Jan 2015 10:17:16 -0500
parents 6156edaa82aa
children 448bb32b8ee6
files mercurial/osutil.c
diffstat 1 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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);