# HG changeset patch # User Yuya Nishihara # Date 2020-07-19 08:24:16 # Node ID 2bc5d15312356080afc7c7746b559d188cd74386 # Parent 04c428e937703e8c9edb2e4f93f51c841baaf2e9 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 @@ -2885,7 +2885,7 @@ PyTypeObject HgRevlogIndex_Type = { */ PyObject *parse_index2(PyObject *self, PyObject *args) { - PyObject *tuple = NULL, *cache = NULL; + PyObject *cache = NULL; indexObject *idx; int ret; @@ -2906,15 +2906,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; }