Patchwork [stable,v2] parsers.c: fix a couple of memory leaks

login
register
mail settings
Submitter Danek Duvall
Date June 12, 2014, 11:08 p.m.
Message ID <ed93ca72e5f22b296243.1402614493@smelly>
Download mbox | patch
Permalink /patch/4983/
State Accepted
Commit 8da100383dc32c1f12dcc3ce8dd4ea38c6281158
Headers show

Comments

Danek Duvall - June 12, 2014, 11:08 p.m.
# HG changeset patch
# User Danek Duvall <danek.duvall@oracle.com>
# Date 1402525864 25200
#      Wed Jun 11 15:31:04 2014 -0700
# Branch stable
# Node ID ed93ca72e5f22b29624394a484668c153020882a
# Parent  b35f8c487e396487e89f98e92da57ac5eb9833af
parsers.c: fix a couple of memory leaks

Patch

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -1299,7 +1299,7 @@  static PyObject *find_deepest(indexObjec
 	static const Py_ssize_t capacity = 24;
 	int *depth, *interesting = NULL;
 	int i, j, v, ninteresting;
-	PyObject *dict = NULL, *keys;
+	PyObject *dict = NULL, *keys = NULL;
 	long *seen = NULL;
 	int maxrev = -1;
 	long final;
@@ -1403,8 +1403,10 @@  static PyObject *find_deepest(indexObjec
 		final |= i;
 		j -= 1;
 	}
-	if (final == 0)
-		return PyList_New(0);
+	if (final == 0) {
+		keys = PyList_New(0);
+		goto bail;
+	}
 
 	dict = PyDict_New();
 	if (dict == NULL)
@@ -1428,19 +1430,13 @@  static PyObject *find_deepest(indexObjec
 
 	keys = PyDict_Keys(dict);
 
-	free(depth);
-	free(seen);
-	free(interesting);
-	Py_DECREF(dict);
-
-	return keys;
 bail:
 	free(depth);
 	free(seen);
 	free(interesting);
 	Py_XDECREF(dict);
 
-	return NULL;
+	return keys;
 }
 
 /*