Patchwork [1,of,2] revlog: fix excessive decref on tuple creation failure in parse_index2()

login
register
mail settings
Submitter Yuya Nishihara
Date July 19, 2020, 10:08 a.m.
Message ID <69b9623330ca581376bb.1595153317@mimosa>
Download mbox | patch
Permalink /patch/46807/
State Accepted
Headers show

Comments

Yuya Nishihara - July 19, 2020, 10:08 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1595147056 -32400
#      Sun Jul 19 17:24:16 2020 +0900
# Node ID 69b9623330ca581376bb215cafe1aac4033216b8
# Parent  739668fe6ef6d54a2ff93fbad9c18886d3a6aa95
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

Patch

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -2889,7 +2889,7 @@  PyTypeObject HgRevlogIndex_Type = {
  */
 PyObject *parse_index2(PyObject *self, PyObject *args)
 {
-	PyObject *tuple = NULL, *cache = NULL;
+	PyObject *cache = NULL;
 	indexObject *idx;
 	int ret;
 
@@ -2910,15 +2910,11 @@  PyObject *parse_index2(PyObject *self, P
 		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;
 }