summaryrefslogtreecommitdiff
path: root/giscanner/giscannermodule.c
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@linux-m68k.org>2011-11-27 20:48:24 +0100
committerColin Walters <walters@verbum.org>2011-12-15 09:52:37 -0500
commitf35167808a98f9ea9aecb2c04af3b31198ea5f60 (patch)
tree7a5a71ea8757253752442cf904b07bbeb8f20e3a /giscanner/giscannermodule.c
parent77c9f9f3eec61e4711dab9317daf7455d1ee31ff (diff)
downloadgobject-introspection-f35167808a98f9ea9aecb2c04af3b31198ea5f60.tar.gz
giscanner: fix use after decref
Decrement reference to temporary string object only after last use of its value.
Diffstat (limited to 'giscanner/giscannermodule.c')
-rw-r--r--giscanner/giscannermodule.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/giscanner/giscannermodule.c b/giscanner/giscannermodule.c
index 86fa2449..81adbd8c 100644
--- a/giscanner/giscannermodule.c
+++ b/giscanner/giscannermodule.c
@@ -569,6 +569,7 @@ static int calc_attrs_length(PyObject *attributes, int indent,
for (i = 0; i < PyList_Size (attributes); ++i)
{
PyObject *tuple, *pyvalue;
+ PyObject *s = NULL;
char *attr, *value;
char *escaped;
@@ -580,12 +581,11 @@ static int calc_attrs_length(PyObject *attributes, int indent,
return -1;
if (PyUnicode_Check(pyvalue)) {
- PyObject *s = PyUnicode_AsUTF8String(pyvalue);
+ s = PyUnicode_AsUTF8String(pyvalue);
if (!s) {
return -1;
}
value = PyString_AsString(s);
- Py_DECREF(s);
} else if (PyString_Check(pyvalue)) {
value = PyString_AsString(pyvalue);
} else {
@@ -597,6 +597,7 @@ static int calc_attrs_length(PyObject *attributes, int indent,
escaped = g_markup_escape_text (value, -1);
attr_length += 2 + strlen(attr) + strlen(escaped) + 2;
g_free(escaped);
+ Py_XDECREF(s);
}
return attr_length + indent + self_indent;
@@ -641,6 +642,7 @@ pygi_collect_attributes (PyObject *self,
for (i = 0; i < PyList_Size (attributes); ++i)
{
PyObject *tuple, *pyvalue;
+ PyObject *s = NULL;
char *attr, *value, *escaped;
tuple = PyList_GetItem (attributes, i);
@@ -667,11 +669,10 @@ pygi_collect_attributes (PyObject *self,
goto out;
if (PyUnicode_Check(pyvalue)) {
- PyObject *s = PyUnicode_AsUTF8String(pyvalue);
+ s = PyUnicode_AsUTF8String(pyvalue);
if (!s)
goto out;
value = PyString_AsString(s);
- Py_DECREF(s);
} else if (PyString_Check(pyvalue)) {
value = PyString_AsString(pyvalue);
} else {
@@ -695,6 +696,7 @@ pygi_collect_attributes (PyObject *self,
g_string_append_c (attr_value, '\"');
if (first)
first = FALSE;
+ Py_XDECREF(s);
}
result = PyUnicode_DecodeUTF8 (attr_value->str, attr_value->len, "strict");