# HG changeset patch # User Bryan O'Sullivan # Date 2013-11-27 05:55:21 # Node ID 9bfa86746c9c1f6ab51deb8f174ffc482417d09f # Parent 40b7c6e4b9934c59c244f0a8b8a44258065b1174 # Parent e57c532c3835f6b244f21815cafcce0df1d272ce Merge diff --git a/mercurial/parsers.c b/mercurial/parsers.c --- a/mercurial/parsers.c +++ b/mercurial/parsers.c @@ -1718,6 +1718,15 @@ static int index_init(indexObject *self, PyObject *data_obj, *inlined_obj; Py_ssize_t size; + /* Initialize before argument-checking to avoid index_dealloc() crash. */ + self->raw_length = 0; + self->added = NULL; + self->cache = NULL; + self->data = NULL; + self->headrevs = NULL; + self->nt = NULL; + self->offsets = NULL; + if (!PyArg_ParseTuple(args, "OO", &data_obj, &inlined_obj)) return -1; if (!PyString_Check(data_obj)) { @@ -1728,12 +1737,7 @@ static int index_init(indexObject *self, self->inlined = inlined_obj && PyObject_IsTrue(inlined_obj); self->data = data_obj; - self->cache = NULL; - self->added = NULL; - self->headrevs = NULL; - self->offsets = NULL; - self->nt = NULL; self->ntlength = self->ntcapacity = 0; self->ntdepth = self->ntsplits = 0; self->ntlookups = self->ntmisses = 0; @@ -1769,7 +1773,7 @@ static PyObject *index_nodemap(indexObje static void index_dealloc(indexObject *self) { _index_clearcaches(self); - Py_DECREF(self->data); + Py_XDECREF(self->data); Py_XDECREF(self->added); PyObject_Del(self); } diff --git a/tests/test-parseindex2.py b/tests/test-parseindex2.py --- a/tests/test-parseindex2.py +++ b/tests/test-parseindex2.py @@ -98,6 +98,14 @@ def parse_index2(data, inline): return list(index), chunkcache def runtest() : + # Check that parse_index2() raises TypeError on bad arguments. + try: + parse_index2(0, True) + except TypeError: + pass + else: + print "Expected to get TypeError." + py_res_1 = py_parseindex(data_inlined, True) c_res_1 = parse_index2(data_inlined, True)