gh-95355: Check tokens[0] after allocating memory (GH-95356)

GH-95355

Automerge-Triggered-By: GH:pablogsal
(cherry picked from commit b946f529ef)

Co-authored-by: Honglin Zhu <zhuhonglin.zhl@alibaba-inc.com>
This commit is contained in:
Miss Islington (bot) 2022-07-28 03:29:50 -07:00 committed by GitHub
parent 7813d976ae
commit d3cc99bdce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 1 deletions

View file

@ -0,0 +1 @@
``_PyPegen_Parser_New`` now properly detects token memory allocation errors. Patch by Honglin Zhu.

View file

@ -744,7 +744,7 @@ _PyPegen_Parser_New(struct tok_state *tok, int start_rule, int flags,
return (Parser *) PyErr_NoMemory();
}
p->tokens[0] = PyMem_Calloc(1, sizeof(Token));
if (!p->tokens) {
if (!p->tokens[0]) {
PyMem_Free(p->tokens);
PyMem_Free(p);
return (Parser *) PyErr_NoMemory();