[PATCH 4 of 6] parsers.c: parse_manifest: fixing refcount of flags
Nicolas Dumazet
nicdumz at gmail.com
Thu Aug 27 13:09:13 UTC 2009
# HG changeset patch
# User Nicolas Dumazet <nicdumz.commits at gmail.com>
# Date 1251375304 -7200
# Node ID 391c057f3497bab711c70afedfabafd45f2f3698
# Parent 84617922fc1b579685869172349c0c679be4b7fc
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