Index: Parser/parsetok.c =================================================================== --- Parser/parsetok.c (revision 74649) +++ Parser/parsetok.c (working copy) @@ -243,16 +243,24 @@ err_ret->text = text; } } else if (tok->encoding != NULL) { + /* nodes manage n_str using PyObject_*, while the 'encoding' was + * allocated using PyObject_ + */ node* r = PyNode_New(encoding_decl); - if (!r) { + if (r) + r->n_str = PyObject_MALLOC(strlen(tok->encoding)+1); + if (!r || !r->n_str) { err_ret->error = E_NOMEM; + if (r) + PyObject_FREE(r); n = NULL; goto done; } - r->n_str = tok->encoding; + strcpy(r->n_str, tok->encoding); + PyMem_FREE(tok->encoding); + tok->encoding = NULL; r->n_nchildren = 1; r->n_child = n; - tok->encoding = NULL; n = r; }