diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2019-03-19 17:17:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-19 17:17:58 (GMT) |
commit | cb90c89de14aab636739b3e810cf949e47b54a0c (patch) | |
tree | 7cd028cd325ae0e3f08ed5e598fe5109efd3a340 /Parser | |
parent | dcf617152e1d4c4a5e7965733928858a9c0936ca (diff) | |
download | cpython-cb90c89de14aab636739b3e810cf949e47b54a0c.zip cpython-cb90c89de14aab636739b3e810cf949e47b54a0c.tar.gz cpython-cb90c89de14aab636739b3e810cf949e47b54a0c.tar.bz2 |
bpo-36367: Free buffer if realloc fails in tokenize.c (GH-12442)
Diffstat (limited to 'Parser')
-rw-r--r-- | Parser/tokenizer.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 8f0a9c8..ad05497 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -649,9 +649,14 @@ translate_newlines(const char *s, int exec_input, struct tok_state *tok) { } *current = '\0'; final_length = current - buf + 1; - if (final_length < needed_length && final_length) + if (final_length < needed_length && final_length) { /* should never fail */ - buf = PyMem_REALLOC(buf, final_length); + char* result = PyMem_REALLOC(buf, final_length); + if (result == NULL) { + PyMem_FREE(buf); + } + buf = result; + } return buf; } @@ -958,6 +963,7 @@ tok_nextc(struct tok_state *tok) newbuf = (char *)PyMem_REALLOC(newbuf, newsize); if (newbuf == NULL) { + PyMem_FREE(tok->buf); tok->done = E_NOMEM; tok->cur = tok->inp; return EOF; |