Merge
authorBryan O'Sullivan <bryano@fb.com>
Tue, 26 Nov 2013 21:55:21 -0800
changeset 20111 9bfa86746c9c
parent 20110 40b7c6e4b993 (current diff)
parent 20109 e57c532c3835 (diff)
child 20112 169f8141ba00
Merge
mercurial/parsers.c
--- a/mercurial/parsers.c	Tue Nov 19 23:49:11 2013 +0530
+++ b/mercurial/parsers.c	Tue Nov 26 21:55:21 2013 -0800
@@ -1718,6 +1718,15 @@
 	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 @@
 
 	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 void index_dealloc(indexObject *self)
 {
 	_index_clearcaches(self);
-	Py_DECREF(self->data);
+	Py_XDECREF(self->data);
 	Py_XDECREF(self->added);
 	PyObject_Del(self);
 }
--- a/tests/test-parseindex2.py	Tue Nov 19 23:49:11 2013 +0530
+++ b/tests/test-parseindex2.py	Tue Nov 26 21:55:21 2013 -0800
@@ -98,6 +98,14 @@
     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)