Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 87b801c

Browse files
committed
Set MemoryError when alloc fails
1 parent 3c52c5a commit 87b801c

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

Python/compile.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,12 +1075,16 @@ compiler_enter_scope(struct compiler *c, identifier name, void *key,
10751075
struct compiler_unit *u;
10761076

10771077
u = PyObject_Malloc(sizeof(struct compiler_unit));
1078+
if (!u) {
1079+
PyErr_NoMemory();
1080+
return 0;
1081+
}
10781082
memset(u, 0, sizeof(struct compiler_unit));
10791083
u->u_argcount = 0;
10801084
u->u_ste = PySymtable_Lookup(c->c_st, key);
10811085
if (!u->u_ste) {
10821086
compiler_unit_free(u);
1083-
return 0;
1087+
return 0;
10841088
}
10851089
Py_INCREF(name);
10861090
u->u_name = name;
@@ -1163,8 +1167,10 @@ compiler_new_block(struct compiler *c)
11631167

11641168
u = c->u;
11651169
b = (basicblock *)PyObject_Malloc(sizeof(basicblock));
1166-
if (b == NULL)
1170+
if (b == NULL) {
1171+
PyErr_NoMemory();
11671172
return NULL;
1173+
}
11681174
memset((void *)b, 0, sizeof(basicblock));
11691175
assert (b->b_next == NULL);
11701176
b->b_list = u->u_blocks;
@@ -3747,8 +3753,10 @@ assemble_init(struct assembler *a, int nblocks, int firstlineno)
37473753
return 0;
37483754
a->a_postorder = (basicblock **)PyObject_Malloc(
37493755
sizeof(basicblock *) * nblocks);
3750-
if (!a->a_postorder)
3756+
if (!a->a_postorder) {
3757+
PyErr_NoMemory();
37513758
return 0;
3759+
}
37523760
return 1;
37533761
}
37543762

0 commit comments

Comments
 (0)