summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristján Valur Jónsson <kristjan@ccpgames.com>2009-09-28 13:08:48 (GMT)
committerKristján Valur Jónsson <kristjan@ccpgames.com>2009-09-28 13:08:48 (GMT)
commitd12f86ce96d3aeb91e9c7f010e303bbc1b8d14da (patch)
treea87951cc46c090b05a4fb032fbf7958cc5666eaf
parentb4fd4d37a1b01620cd1bf66d61dcd481b13db411 (diff)
downloadcpython-d12f86ce96d3aeb91e9c7f010e303bbc1b8d14da.zip
cpython-d12f86ce96d3aeb91e9c7f010e303bbc1b8d14da.tar.gz
cpython-d12f86ce96d3aeb91e9c7f010e303bbc1b8d14da.tar.bz2
http://bugs.python.org/issue6836
A memory block allocated with one API was being handed over to an object that used another API to release it.
-rw-r--r--Parser/parsetok.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/Parser/parsetok.c b/Parser/parsetok.c
index 71792dd..3994add 100644
--- a/Parser/parsetok.c
+++ b/Parser/parsetok.c
@@ -243,16 +243,24 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
err_ret->text = text;
}
} else if (tok->encoding != NULL) {
+ /* 'nodes->n_str' uses PyObject_*, while 'tok->encoding' was
+ * allocated using PyMem_
+ */
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;
}