Patchwork [2,of,5,STABLE] xdiff: fix leak in hunk_consumer()

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 5, 2018, 1:58 p.m.
Message ID <c1556580015504061ab7.1536155904@mimosa>
Download mbox | patch
Permalink /patch/34337/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 5, 2018, 1:58 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# 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.

Patch

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)