[PATCH] lazymanifest: check more return values in filtercopy

Augie Fackler raf at durin42.com
Tue Jan 5 15:57:59 UTC 2016


# HG changeset patch
# User Augie Fackler <raf at durin42.com>
# Date 1451586702 18000
#      Thu Dec 31 13:31:42 2015 -0500
# Node ID 700ae5816d662e0e5dde55c68944329b6eb1b7c0
# Parent  0bc71f45d3623b231cc3975b48feccce79d1231e
lazymanifest: check more return values in filtercopy

Spotted by Bryan O'Sullivan (and vexingly not the static analyzer I've
been using.)

diff --git a/mercurial/manifest.c b/mercurial/manifest.c
--- a/mercurial/manifest.c
+++ b/mercurial/manifest.c
@@ -707,11 +707,20 @@ static lazymanifest *lazymanifest_filter
 	copy->pydata = self->pydata;
 	Py_INCREF(self->pydata);
 	for (i = 0; i < self->numlines; i++) {
-		PyObject *arg = PyString_FromString(self->lines[i].start);
-		PyObject *arglist = PyTuple_Pack(1, arg);
-		PyObject *result = PyObject_CallObject(matchfn, arglist);
+		PyObject *arg = NULL, *arglist = NULL, *result = NULL;
+		arg = PyString_FromString(self->lines[i].start);
+		if (!arg) {
+			PyErr_SetString(PyExc_TypeError,
+					"couldn't pack filename");
+			return NULL;
+		}
+		arglist = PyTuple_Pack(1, arg);
+		Py_DECREF(arg);
+		if (!arglist) {
+			return NULL;
+		}
+		result = PyObject_CallObject(matchfn, arglist);
 		Py_DECREF(arglist);
-		Py_DECREF(arg);
 		/* if the callback raised an exception, just let it
 		 * through and give up */
 		if (!result) {


More information about the Mercurial-devel mailing list