Patchwork [4,of,5,stable,cpychecker] osutil: fix leak of stat in makestat when Py_BuildValue fails

login
register
mail settings
Submitter Augie Fackler
Date Jan. 27, 2015, 3:26 p.m.
Message ID <6c71c9d9336df3a27325.1422372395@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/7563/
State Accepted
Commit 1f3b94e8dc4012051482f54b51a07ff66e15dee2
Headers show

Comments

Augie Fackler - Jan. 27, 2015, 3:26 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1422371663 18000
#      Tue Jan 27 10:14:23 2015 -0500
# Branch stable
# Node ID 6c71c9d9336df3a27325b956aeb70fe6d2d953d1
# Parent  23397a8fe0d25668f79c818230c70e2cfd03c110
osutil: fix leak of stat in makestat when Py_BuildValue fails

Spotted with cpychecker.
Matt Mackall - Jan. 27, 2015, 10:43 p.m.
On Tue, 2015-01-27 at 10:26 -0500, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1422371663 18000
> #      Tue Jan 27 10:14:23 2015 -0500
> # Branch stable
> # Node ID 6c71c9d9336df3a27325b956aeb70fe6d2d953d1
> # Parent  23397a8fe0d25668f79c818230c70e2cfd03c110
> osutil: fix leak of stat in makestat when Py_BuildValue fails

I've queued these first four, thanks.

Patch

diff --git a/mercurial/osutil.c b/mercurial/osutil.c
--- a/mercurial/osutil.c
+++ b/mercurial/osutil.c
@@ -288,7 +288,7 @@  static PyObject *makestat(const struct s
 
 static PyObject *_listdir(char *path, int pathlen, int keepstat, char *skip)
 {
-	PyObject *list, *elem, *stat, *ret = NULL;
+	PyObject *list, *elem, *stat = NULL, *ret = NULL;
 	char fullpath[PATH_MAX + 10];
 	int kind, err;
 	struct stat st;
@@ -369,6 +369,7 @@  static PyObject *_listdir(char *path, in
 			elem = Py_BuildValue("si", ent->d_name, kind);
 		if (!elem)
 			goto error;
+		stat = NULL;
 
 		PyList_Append(list, elem);
 		Py_DECREF(elem);
@@ -379,6 +380,7 @@  static PyObject *_listdir(char *path, in
 
 error:
 	Py_DECREF(list);
+	Py_XDECREF(stat);
 error_list:
 	closedir(dir);
 error_dir: