diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2023-01-16 18:45:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-16 18:45:37 (GMT) |
commit | 1de4395f62bb140563761ef5cbdf46accef3c550 (patch) | |
tree | 9186fb64a869592f9f9c46b0dfb9e532e5e43790 | |
parent | 30753c37c6d00929af6afb5e0bc20bed4656d6b6 (diff) | |
download | cpython-1de4395f62bb140563761ef5cbdf46accef3c550.zip cpython-1de4395f62bb140563761ef5cbdf46accef3c550.tar.gz cpython-1de4395f62bb140563761ef5cbdf46accef3c550.tar.bz2 |
gh-101046: Fix a potential memory leak in the parser when raising MemoryError (#101051)
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2023-01-15-03-26-04.gh-issue-101046.g2CM4S.rst | 2 | ||||
-rw-r--r-- | Parser/parser.c | 108 | ||||
-rw-r--r-- | Tools/peg_generator/pegen/c_generator.py | 2 |
3 files changed, 111 insertions, 1 deletions
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-01-15-03-26-04.gh-issue-101046.g2CM4S.rst b/Misc/NEWS.d/next/Core and Builtins/2023-01-15-03-26-04.gh-issue-101046.g2CM4S.rst new file mode 100644 index 0000000..f600473 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-01-15-03-26-04.gh-issue-101046.g2CM4S.rst @@ -0,0 +1,2 @@ +Fix a possible memory leak in the parser when raising :exc:`MemoryError`. +Patch by Pablo Galindo diff --git a/Parser/parser.c b/Parser/parser.c index d0bc259..845c173 100644 --- a/Parser/parser.c +++ b/Parser/parser.c @@ -23803,6 +23803,7 @@ _loop0_1_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -23872,6 +23873,7 @@ _loop0_2_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -23941,6 +23943,7 @@ _loop1_3_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -24024,6 +24027,7 @@ _loop0_5_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -24607,6 +24611,7 @@ _loop1_14_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -24853,6 +24858,7 @@ _loop0_19_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -24973,6 +24979,7 @@ _loop0_21_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -25189,6 +25196,7 @@ _loop0_24_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -25258,6 +25266,7 @@ _loop1_25_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -25341,6 +25350,7 @@ _loop0_27_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -25508,6 +25518,7 @@ _loop0_30_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -25666,6 +25677,7 @@ _loop1_32_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -25884,6 +25896,7 @@ _loop0_36_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -25953,6 +25966,7 @@ _loop0_37_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -26022,6 +26036,7 @@ _loop0_38_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -26091,6 +26106,7 @@ _loop1_39_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -26165,6 +26181,7 @@ _loop0_40_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -26234,6 +26251,7 @@ _loop1_41_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -26308,6 +26326,7 @@ _loop1_42_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -26382,6 +26401,7 @@ _loop1_43_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -26456,6 +26476,7 @@ _loop0_44_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -26525,6 +26546,7 @@ _loop1_45_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -26599,6 +26621,7 @@ _loop0_46_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -26668,6 +26691,7 @@ _loop1_47_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -26742,6 +26766,7 @@ _loop0_48_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -26811,6 +26836,7 @@ _loop0_49_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -26880,6 +26906,7 @@ _loop1_50_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -26963,6 +26990,7 @@ _loop0_52_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -27083,6 +27111,7 @@ _loop0_54_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -27203,6 +27232,7 @@ _loop0_56_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -27323,6 +27353,7 @@ _loop0_58_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -27511,6 +27542,7 @@ _loop1_60_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -27585,6 +27617,7 @@ _loop1_61_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -27753,6 +27786,7 @@ _loop1_64_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -27836,6 +27870,7 @@ _loop0_66_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -28226,6 +28261,7 @@ _loop0_72_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -28346,6 +28382,7 @@ _loop0_74_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -28524,6 +28561,7 @@ _loop0_77_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -28644,6 +28682,7 @@ _loop0_79_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -28755,6 +28794,7 @@ _loop1_80_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -28829,6 +28869,7 @@ _loop1_81_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -28912,6 +28953,7 @@ _loop0_83_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -29023,6 +29065,7 @@ _loop1_84_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -29097,6 +29140,7 @@ _loop1_85_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -29171,6 +29215,7 @@ _loop1_86_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -29298,6 +29343,7 @@ _loop0_89_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -29745,6 +29791,7 @@ _loop0_95_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -29814,6 +29861,7 @@ _loop0_96_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -29883,6 +29931,7 @@ _loop0_97_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -29952,6 +30001,7 @@ _loop1_98_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -30026,6 +30076,7 @@ _loop0_99_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -30095,6 +30146,7 @@ _loop1_100_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -30169,6 +30221,7 @@ _loop1_101_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -30243,6 +30296,7 @@ _loop1_102_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -30317,6 +30371,7 @@ _loop0_103_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -30386,6 +30441,7 @@ _loop1_104_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -30460,6 +30516,7 @@ _loop0_105_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -30529,6 +30586,7 @@ _loop1_106_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -30603,6 +30661,7 @@ _loop0_107_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -30672,6 +30731,7 @@ _loop1_108_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -30746,6 +30806,7 @@ _loop1_109_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -30879,6 +30940,7 @@ _loop0_112_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -30990,6 +31052,7 @@ _loop1_113_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -31064,6 +31127,7 @@ _loop0_114_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -31133,6 +31197,7 @@ _loop0_115_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -31271,6 +31336,7 @@ _loop0_118_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -31439,6 +31505,7 @@ _loop0_121_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -31559,6 +31626,7 @@ _loop0_123_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -31679,6 +31747,7 @@ _loop0_125_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -31799,6 +31868,7 @@ _loop0_127_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -31910,6 +31980,7 @@ _loop0_128_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -31988,6 +32059,7 @@ _loop0_130_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -32099,6 +32171,7 @@ _loop1_131_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -32223,6 +32296,7 @@ _loop0_134_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -32343,6 +32417,7 @@ _loop0_136_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -32463,6 +32538,7 @@ _loop0_138_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -32583,6 +32659,7 @@ _loop0_140_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -32703,6 +32780,7 @@ _loop0_142_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -33505,6 +33583,7 @@ _loop0_154_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -33574,6 +33653,7 @@ _loop0_155_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -33643,6 +33723,7 @@ _loop0_156_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -34021,6 +34102,7 @@ _loop0_162_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -34090,6 +34172,7 @@ _loop0_163_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -34159,6 +34242,7 @@ _loop0_164_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -34228,6 +34312,7 @@ _loop1_165_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -34360,6 +34445,7 @@ _loop0_167_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -34487,6 +34573,7 @@ _loop0_169_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -34556,6 +34643,7 @@ _loop1_170_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -34807,6 +34895,7 @@ _loop0_174_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -35011,6 +35100,7 @@ _loop1_177_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -35143,6 +35233,7 @@ _loop0_179_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -35212,6 +35303,7 @@ _loop0_180_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -35281,6 +35373,7 @@ _loop0_181_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -35359,6 +35452,7 @@ _loop0_183_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -35528,6 +35622,7 @@ _loop0_185_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -35655,6 +35750,7 @@ _loop0_187_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -35724,6 +35820,7 @@ _loop1_188_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -35798,6 +35895,7 @@ _loop1_189_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -35991,6 +36089,7 @@ _loop0_192_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -36281,6 +36380,7 @@ _loop0_197_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -36401,6 +36501,7 @@ _loop0_199_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -36521,6 +36622,7 @@ _loop0_201_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -36641,6 +36743,7 @@ _loop0_203_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -36810,6 +36913,7 @@ _loop0_205_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -36879,6 +36983,7 @@ _loop1_206_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -36995,6 +37100,7 @@ _loop0_208_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -37064,6 +37170,7 @@ _loop1_209_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; @@ -37592,6 +37699,7 @@ _loop0_221_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { + PyMem_Free(_children); p->error_indicator = 1; PyErr_NoMemory(); p->level--; diff --git a/Tools/peg_generator/pegen/c_generator.py b/Tools/peg_generator/pegen/c_generator.py index 31bb505..c41d87b 100644 --- a/Tools/peg_generator/pegen/c_generator.py +++ b/Tools/peg_generator/pegen/c_generator.py @@ -801,7 +801,7 @@ class CParserGenerator(ParserGenerator, GrammarVisitor): self.print( "void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *));" ) - self.out_of_memory_return(f"!_new_children") + self.out_of_memory_return(f"!_new_children", cleanup_code="PyMem_Free(_children);") self.print("_children = _new_children;") self.print("}") self.print("_children[_n++] = _res;") |