changeset 45173:2bc5d1531235

revlog: fix excessive decref on tuple creation failure in parse_index2() Since Py_BuildValue() steals the ownership of "N" arguments, these objects would already be freed if Py_BuildValue() returned NULL. https://github.com/python/cpython/blob/2.7/Python/modsupport.c#L292
author Yuya Nishihara <yuya@tcha.org>
date Sun, 19 Jul 2020 17:24:16 +0900
parents 04c428e93770
children f93a4e3d35ab
files mercurial/cext/revlog.c
diffstat 1 files changed, 2 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cext/revlog.c	Mon Jul 20 17:38:01 2020 +0200
+++ b/mercurial/cext/revlog.c	Sun Jul 19 17:24:16 2020 +0900
@@ -2885,7 +2885,7 @@
  */
 PyObject *parse_index2(PyObject *self, PyObject *args)
 {
-	PyObject *tuple = NULL, *cache = NULL;
+	PyObject *cache = NULL;
 	indexObject *idx;
 	int ret;
 
@@ -2906,15 +2906,11 @@
 		Py_INCREF(cache);
 	}
 
-	tuple = Py_BuildValue("NN", idx, cache);
-	if (!tuple)
-		goto bail;
-	return tuple;
+	return Py_BuildValue("NN", idx, cache);
 
 bail:
 	Py_XDECREF(idx);
 	Py_XDECREF(cache);
-	Py_XDECREF(tuple);
 	return NULL;
 }