[PATCH 1 of 2] revlog: fix excessive decref on tuple creation failure in parse_index2()
Yuya Nishihara
yuya at tcha.org
Sun Jul 19 10:08:37 UTC 2020
# HG changeset patch
# User Yuya Nishihara <yuya at 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
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;
}
More information about the Mercurial-devel
mailing list