From b15ba9229521482810af8a5a03337c6966511871 Mon Sep 17 00:00:00 2001 From: Augie Fackler Date: Tue, 27 Jan 2015 10:14:23 -0500 Subject: [PATCH] osutil: fix leak of stat in makestat when Py_BuildValue fails Spotted with cpychecker. --- mercurial/osutil.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mercurial/osutil.c b/mercurial/osutil.c index ceabc16768..3331c0cd58 100644 --- a/mercurial/osutil.c +++ b/mercurial/osutil.c @@ -288,7 +288,7 @@ static PyObject *makestat(const struct stat *st) 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, int pathlen, int keepstat, char *skip) 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, int pathlen, int keepstat, char *skip) error: Py_DECREF(list); + Py_XDECREF(stat); error_list: closedir(dir); error_dir: