Skip to content

Commit

Permalink
bpo-36367: Free buffer if realloc fails in tokenize.c (pythonGH-12442)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablogsal authored Mar 19, 2019
1 parent dcf6171 commit cb90c89
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit cb90c89

Please sign in to comment.