diff -r c91e7f707562 Modules/_elementtree.c --- a/Modules/_elementtree.c Tue Jul 09 00:49:03 2013 +0200 +++ b/Modules/_elementtree.c Tue Jul 09 02:02:04 2013 +0200 @@ -224,24 +224,24 @@ create_new_element(PyObject* tag, PyObje return NULL; self->extra = NULL; + Py_INCREF(tag); + self->tag = tag; + + Py_INCREF(Py_None); + self->text = Py_None; + + Py_INCREF(Py_None); + self->tail = Py_None; + + self->weakreflist = NULL; + if (attrib != Py_None && !is_empty_dict(attrib)) { if (create_extra(self, attrib) < 0) { - PyObject_Del(self); + PyObject_GC_Del(self); return NULL; } } - Py_INCREF(tag); - self->tag = tag; - - Py_INCREF(Py_None); - self->text = Py_None; - - Py_INCREF(Py_None); - self->tail = Py_None; - - self->weakreflist = NULL; - ALLOC(sizeof(ElementObject), "create element"); PyObject_GC_Track(self); return (PyObject*) self; @@ -374,8 +374,10 @@ element_resize(ElementObject* self, int /* make sure self->children can hold the given number of extra elements. set an exception and return -1 if allocation failed */ - if (!self->extra) - create_extra(self, NULL); + if (!self->extra) { + if (create_extra(self, NULL) < 0) + return -1; + } size = self->extra->length + extra; @@ -527,8 +529,9 @@ subelement(PyObject *self, PyObject *arg } elem = create_new_element(tag, attrib); - Py_DECREF(attrib); + if (elem == NULL) + return NULL; if (element_add_subelement(parent, elem) < 0) { Py_DECREF(elem); @@ -1267,8 +1270,10 @@ element_insert(ElementObject* self, PyOb &Element_Type, &element)) return NULL; - if (!self->extra) - create_extra(self, NULL); + if (!self->extra) { + if (create_extra(self, NULL) < 0) + return NULL; + } if (index < 0) { index += self->extra->length; @@ -1409,8 +1414,10 @@ element_set(ElementObject* self, PyObjec if (!PyArg_ParseTuple(args, "OO:set", &key, &value)) return NULL; - if (!self->extra) - create_extra(self, NULL); + if (!self->extra) { + if (create_extra(self, NULL) < 0) + return NULL; + } attrib = element_get_attrib(self); if (!attrib) @@ -1525,8 +1532,10 @@ element_ass_subscr(PyObject* self_, PyOb PyObject* recycle = NULL; PyObject* seq = NULL; - if (!self->extra) - create_extra(self, NULL); + if (!self->extra) { + if (create_extra(self, NULL) < 0) + return -1; + } if (PySlice_GetIndicesEx(item, self->extra->length, @@ -1741,7 +1750,7 @@ element_getattro(ElementObject* self, Py return res; } else if (strcmp(name, "text") == 0) { res = element_get_text(self); - Py_INCREF(res); + Py_XINCREF(res); return res; } @@ -1756,8 +1765,10 @@ element_getattro(ElementObject* self, Py res = element_get_tail(self); } else if (strcmp(name, "attrib") == 0) { PyErr_Clear(); - if (!self->extra) - create_extra(self, NULL); + if (!self->extra) { + if (create_extra(self, NULL) < 0) + return NULL; + } res = element_get_attrib(self); } @@ -1777,7 +1788,9 @@ element_setattro(ElementObject* self, Py if (name == NULL) { return -1; - } else if (strcmp(name, "tag") == 0) { + } + + if (strcmp(name, "tag") == 0) { Py_DECREF(self->tag); self->tag = value; Py_INCREF(self->tag); @@ -1790,8 +1803,10 @@ element_setattro(ElementObject* self, Py self->tail = value; Py_INCREF(self->tail); } else if (strcmp(name, "attrib") == 0) { - if (!self->extra) - create_extra(self, NULL); + if (!self->extra) { + if (create_extra(self, NULL) < 0) + return -1; + } Py_DECREF(self->extra->attrib); self->extra->attrib = value; Py_INCREF(self->extra->attrib); @@ -2123,15 +2138,15 @@ create_elementiter(ElementObject *self, if (star && PyObject_RichCompareBool(tag, star, Py_EQ) == 1) tag = Py_None; - Py_XDECREF(star); + + Py_INCREF(tag); it->sought_tag = tag; it->root_done = 0; it->gettext = gettext; + Py_INCREF(self); it->root_element = self; - Py_INCREF(self); - Py_INCREF(tag); PyObject_GC_Track(it); return (PyObject *)it; @@ -2715,6 +2730,10 @@ makeuniversal(XMLParserObject* self, con if (i != size) { /* convert to universal name */ tag = PyBytes_FromStringAndSize(NULL, size+1); + if (tag == NULL) { + Py_DECREF(key); + return NULL; + } p = PyBytes_AS_STRING(tag); p[0] = '{'; memcpy(p+1, string, size); diff -r c91e7f707562 Modules/_pickle.c --- a/Modules/_pickle.c Tue Jul 09 00:49:03 2013 +0200 +++ b/Modules/_pickle.c Tue Jul 09 02:02:04 2013 +0200 @@ -774,18 +774,15 @@ static PicklerObject * self->fast_nesting = 0; self->fix_imports = 0; self->fast_memo = NULL; - - self->memo = PyMemoTable_New(); - if (self->memo == NULL) { - Py_DECREF(self); - return NULL; - } self->max_output_len = WRITE_BUF_SIZE; self->output_len = 0; + + self->memo = PyMemoTable_New(); self->output_buffer = PyBytes_FromStringAndSize(NULL, self->max_output_len); - if (self->output_buffer == NULL) { - Py_DECREF(self); + if (self->memo == NULL + || self->output_buffer == NULL) { + PyObject_GC_Del(self); return NULL; } return self; @@ -1136,20 +1133,6 @@ static UnpicklerObject * if (self == NULL) return NULL; - self->stack = (Pdata *)Pdata_New(); - if (self->stack == NULL) { - Py_DECREF(self); - return NULL; - } - memset(&self->buffer, 0, sizeof(Py_buffer)); - - self->memo_size = 32; - self->memo = _Unpickler_NewMemo(self->memo_size); - if (self->memo == NULL) { - Py_DECREF(self); - return NULL; - } - self->arg = NULL; self->pers_func = NULL; self->input_buffer = NULL; @@ -1167,6 +1150,23 @@ static UnpicklerObject * self->marks_size = 0; self->proto = 0; self->fix_imports = 0; + self->stack = NULL; + memset(&self->buffer, 0, sizeof(Py_buffer)); + self->memo_size = 32; + self->memo = NULL; + + self->stack = (Pdata *)Pdata_New(); + if (self->stack == NULL) { + Py_DECREF(self); + return NULL; + } + + self->memo_size = 32; + self->memo = _Unpickler_NewMemo(self->memo_size); + if (self->memo == NULL) { + Py_DECREF(self); + return NULL; + } return self; } diff -r c91e7f707562 Modules/pyexpat.c --- a/Modules/pyexpat.c Tue Jul 09 00:49:03 2013 +0200 +++ b/Modules/pyexpat.c Tue Jul 09 02:02:04 2013 +0200 @@ -1183,13 +1183,6 @@ newxmlparseobject(char *encoding, char * /* namespace_separator is either NULL or contains one char + \0 */ self->itself = XML_ParserCreate_MM(encoding, &ExpatMemoryHandler, namespace_separator); -#if ((XML_MAJOR_VERSION >= 2) && (XML_MINOR_VERSION >= 1)) || defined(XML_HAS_SET_HASH_SALT) - /* This feature was added upstream in libexpat 2.1.0. Our expat copy - * has a backport of this feature where we also define XML_HAS_SET_HASH_SALT - * to indicate that we can still use it. */ - XML_SetHashSalt(self->itself, - (unsigned long)_Py_HashSecret.prefix); -#endif self->intern = intern; Py_XINCREF(self->intern); PyObject_GC_Track(self); @@ -1199,6 +1192,13 @@ newxmlparseobject(char *encoding, char * Py_DECREF(self); return NULL; } +#if ((XML_MAJOR_VERSION >= 2) && (XML_MINOR_VERSION >= 1)) || defined(XML_HAS_SET_HASH_SALT) + /* This feature was added upstream in libexpat 2.1.0. Our expat copy + * has a backport of this feature where we also define XML_HAS_SET_HASH_SALT + * to indicate that we can still use it. */ + XML_SetHashSalt(self->itself, + (unsigned long)_Py_HashSecret.prefix); +#endif XML_SetUserData(self->itself, (void *)self); XML_SetUnknownEncodingHandler(self->itself, (XML_UnknownEncodingHandler) PyUnknownEncodingHandler, NULL); diff -r c91e7f707562 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Tue Jul 09 00:49:03 2013 +0200 +++ b/Objects/unicodeobject.c Tue Jul 09 02:02:04 2013 +0200 @@ -122,16 +122,14 @@ extern "C" { /* true if the Unicode object has an allocated UTF-8 memory block (not shared with other data) */ #define _PyUnicode_HAS_UTF8_MEMORY(op) \ - (assert(_PyUnicode_CHECK(op)), \ - (!PyUnicode_IS_COMPACT_ASCII(op) \ + ((!PyUnicode_IS_COMPACT_ASCII(op) \ && _PyUnicode_UTF8(op) \ && _PyUnicode_UTF8(op) != PyUnicode_DATA(op))) /* true if the Unicode object has an allocated wstr memory block (not shared with other data) */ #define _PyUnicode_HAS_WSTR_MEMORY(op) \ - (assert(_PyUnicode_CHECK(op)), \ - (_PyUnicode_WSTR(op) && \ + ((_PyUnicode_WSTR(op) && \ (!PyUnicode_IS_READY(op) || \ _PyUnicode_WSTR(op) != PyUnicode_DATA(op)))) diff -r c91e7f707562 Parser/parsetok.c --- a/Parser/parsetok.c Tue Jul 09 00:49:03 2013 +0200 +++ b/Parser/parsetok.c Tue Jul 09 02:02:04 2013 +0200 @@ -178,7 +178,6 @@ parsetok(struct tok_state *tok, grammar len = b - a; /* XXX this may compute NULL - NULL */ str = (char *) PyObject_MALLOC(len + 1); if (str == NULL) { - fprintf(stderr, "no mem for next token\n"); err_ret->error = E_NOMEM; break; } diff -r c91e7f707562 Python/compile.c --- a/Python/compile.c Tue Jul 09 00:49:03 2013 +0200 +++ b/Python/compile.c Tue Jul 09 02:02:04 2013 +0200 @@ -2316,8 +2316,11 @@ compiler_import(struct compiler *c, stmt identifier tmp = alias->name; Py_ssize_t dot = PyUnicode_FindChar( alias->name, '.', 0, PyUnicode_GET_LENGTH(alias->name), 1); - if (dot != -1) + if (dot != -1) { tmp = PyUnicode_Substring(alias->name, 0, dot); + if (tmp == NULL) + return 0; + } r = compiler_nameop(c, tmp, Store); if (dot != -1) { Py_DECREF(tmp); diff -r c91e7f707562 Python/symtable.c --- a/Python/symtable.c Tue Jul 09 00:49:03 2013 +0200 +++ b/Python/symtable.c Tue Jul 09 02:02:04 2013 +0200 @@ -37,25 +37,13 @@ ste_new(struct symtable *st, identifier ste->ste_table = st; ste->ste_id = k; /* ste owns reference to k */ + Py_INCREF(name); ste->ste_name = name; - Py_INCREF(name); ste->ste_symbols = NULL; ste->ste_varnames = NULL; ste->ste_children = NULL; - ste->ste_symbols = PyDict_New(); - if (ste->ste_symbols == NULL) - goto fail; - - ste->ste_varnames = PyList_New(0); - if (ste->ste_varnames == NULL) - goto fail; - - ste->ste_children = PyList_New(0); - if (ste->ste_children == NULL) - goto fail; - ste->ste_directives = NULL; ste->ste_type = block; @@ -79,6 +67,14 @@ ste_new(struct symtable *st, identifier ste->ste_returns_value = 0; ste->ste_needs_class_closure = 0; + ste->ste_symbols = PyDict_New(); + ste->ste_varnames = PyList_New(0); + ste->ste_children = PyList_New(0); + if (ste->ste_symbols == NULL + || ste->ste_varnames == NULL + || ste->ste_children == NULL) + goto fail; + if (PyDict_SetItem(st->st_blocks, ste->ste_id, (PyObject *)ste) < 0) goto fail;