diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-03-20 12:03:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-20 12:03:41 (GMT) |
commit | 469b0a50d990bcb441910b23194c131e403c2833 (patch) | |
tree | c4395c374d969dee1b342b7fbdb0799572b9e17d | |
parent | 07b8018d75f3d4495708cf1d4175f33b40e13d30 (diff) | |
download | cpython-469b0a50d990bcb441910b23194c131e403c2833.zip cpython-469b0a50d990bcb441910b23194c131e403c2833.tar.gz cpython-469b0a50d990bcb441910b23194c131e403c2833.tar.bz2 |
bpo-36367: Free buffer if realloc fails in tokenize.c (GH-12442) (GH-12470)
(cherry picked from commit cb90c89de14aab636739b3e810cf949e47b54a0c)
-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 c6e61df..6d7869c 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -656,9 +656,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; } @@ -974,6 +979,7 @@ tok_nextc(register 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; |