[PATCH] parsers.c: parse_manifest: fixing refcount of flags

Nicolas Dumazet nicdumz at gmail.com
Fri Sep 4 16:40:21 CDT 2009


# HG changeset patch
# User Nicolas Dumazet <nicdumz.commits at gmail.com>
# Date 1251375304 -7200
# Node ID b751b3467233ccabee1c41a7a7ee997cc375aad5
# Parent  545f9f3f5273d9955f200c5146d12024063bf143
parsers.c: parse_manifest: fixing refcount of flags

When flags was DECREF'ed, scope was referencing to the outer variable,
outside of the block.
It was in fact always NULL: the real Python object was never decref'ed.

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -65,7 +65,6 @@
 
 	for (start = cur = str, zero = NULL; cur < str + len; cur++) {
 		PyObject *file = NULL, *node = NULL;
-		PyObject *flags = NULL;
 		int nlen;
 
 		if (!*cur) {
@@ -94,12 +93,14 @@
 		if (nlen > 40) {
 			PyObject *flags;
 
-			flags = PyString_FromStringAndSize(zero + 41,
-							   nlen - 40);
-			if (!flags)
-				goto bail;
+			flags = PyString_FromStringAndSize(zero + 41, nlen - 40);
 
-			if (PyDict_SetItem(fdict, file, flags) == -1)
+			int success = -1;
+			if (flags) {
+				success = PyDict_SetItem(fdict, file, flags);
+				Py_DECREF(flags);
+			}
+			if (!flags || success == -1)
 				goto bail;
 		}
 
@@ -109,12 +110,10 @@
 		start = cur + 1;
 		zero = NULL;
 
-		Py_XDECREF(flags);
 		Py_XDECREF(node);
 		Py_XDECREF(file);
 		continue;
 	bail:
-		Py_XDECREF(flags);
 		Py_XDECREF(node);
 		Py_XDECREF(file);
 		goto quit;


More information about the Mercurial-devel mailing list