From patchwork Wed Sep 5 13:58:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2,of,5,STABLE] xdiff: fix leak in hunk_consumer() From: Yuya Nishihara X-Patchwork-Id: 34337 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Wed, 05 Sep 2018 22:58:24 +0900 # HG changeset patch # User Yuya Nishihara # Date 1536153041 -32400 # Wed Sep 05 22:10:41 2018 +0900 # Branch stable # Node ID c1556580015504061ab7d1e48e81f5514adc60ac # Parent 33c58a7ff5d54660c5c15a007d8297119cf9ab82 xdiff: fix leak in hunk_consumer() Spotted by ASAN. Since PyList_Append() does not "steal" a reference, Py_DECREF() is always required. Perhaps, this is the largest leak in this series. diff --git a/mercurial/cext/bdiff.c b/mercurial/cext/bdiff.c --- a/mercurial/cext/bdiff.c +++ b/mercurial/cext/bdiff.c @@ -256,13 +256,12 @@ static int hunk_consumer(int64_t a1, int { PyObject *rl = (PyObject *)priv; PyObject *m = Py_BuildValue("LLLL", a1, a2, b1, b2); + int r; if (!m) return -1; - if (PyList_Append(rl, m) != 0) { - Py_DECREF(m); - return -1; - } - return 0; + r = PyList_Append(rl, m); + Py_DECREF(m); + return r; } static PyObject *xdiffblocks(PyObject *self, PyObject *args)