From f35167808a98f9ea9aecb2c04af3b31198ea5f60 Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Sun, 27 Nov 2011 20:48:24 +0100 Subject: giscanner: fix use after decref Decrement reference to temporary string object only after last use of its value. --- giscanner/giscannermodule.c | 10 ++++++---- 1 file 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"); -- cgit v1.2.1