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

#95355

Automerge-Triggered-By: GH:pablogsal
This commit is contained in:
Honglin Zhu 2022-07-28 18:00:34 +08:00 committed by GitHub
parent e16d4ed590
commit b946f529ef
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

@ -738,7 +738,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();