@@ -656,9 +656,14 @@ translate_newlines(const char *s, int exec_input, struct tok_state *tok) {
|
656 | 656 | } |
657 | 657 | *current = '\0'; |
658 | 658 | final_length = current - buf + 1; |
659 | | -if (final_length < needed_length && final_length) |
| 659 | +if (final_length < needed_length && final_length) { |
660 | 660 | /* should never fail */ |
661 | | -buf = PyMem_REALLOC(buf, final_length); |
| 661 | +char* result = PyMem_REALLOC(buf, final_length); |
| 662 | +if (result == NULL) { |
| 663 | +PyMem_FREE(buf); |
| 664 | + } |
| 665 | +buf = result; |
| 666 | + } |
662 | 667 | return buf; |
663 | 668 | } |
664 | 669 | |
@@ -974,6 +979,7 @@ tok_nextc(register struct tok_state *tok)
|
974 | 979 | newbuf = (char *)PyMem_REALLOC(newbuf, |
975 | 980 | newsize); |
976 | 981 | if (newbuf == NULL) { |
| 982 | +PyMem_FREE(tok->buf); |
977 | 983 | tok->done = E_NOMEM; |
978 | 984 | tok->cur = tok->inp; |
979 | 985 | return EOF; |
|