diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-03-20 13:03:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-20 13:03:11 +0100 |
commit | 65b9849f0f07a000d751c96d9d711aeb24c95224 (patch) | |
tree | 729ed6a4c3a8807be0c583d8476ab679b61d101e /Parser | |
parent | 756cfd88920c2349d4546024856c406409b0ab7b (diff) | |
download | cpython-git-65b9849f0f07a000d751c96d9d711aeb24c95224.tar.gz |
bpo-36367: Free buffer if realloc fails in tokenize.c (GH-12442) (GH-12471)
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 1a36f1c384..34722f85b9 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -733,9 +733,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; } @@ -1050,6 +1055,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; |