@@ -300,8 +300,11 @@ PyCodeObject *
300300PyNode_Compile (struct _node * n , const char * filename )
301301{
302302 PyCodeObject * co = NULL ;
303+ mod_ty mod ;
303304 PyArena * arena = PyArena_New ();
304- mod_ty mod = PyAST_FromNode (n , NULL , filename , arena );
305+ if (!arena )
306+ return NULL ;
307+ mod = PyAST_FromNode (n , NULL , filename , arena );
305308 if (mod )
306309 co = PyAST_Compile (mod , filename , NULL , arena );
307310 PyArena_Free (arena );
@@ -615,8 +618,10 @@ markblocks(unsigned char *code, int len)
615618 unsigned int * blocks = (unsigned int * )PyMem_Malloc (len * sizeof (int ));
616619 int i ,j , opcode , blockcnt = 0 ;
617620
618- if (blocks == NULL )
621+ if (blocks == NULL ) {
622+ PyErr_NoMemory ();
619623 return NULL ;
624+ }
620625 memset (blocks , 0 , len * sizeof (int ));
621626
622627 /* Mark labels in the first pass */
@@ -1071,14 +1076,14 @@ compiler_unit_free(struct compiler_unit *u)
10711076 PyObject_Free ((void * )b );
10721077 b = next ;
10731078 }
1074- Py_XDECREF (u -> u_ste );
1075- Py_XDECREF (u -> u_name );
1076- Py_XDECREF (u -> u_consts );
1077- Py_XDECREF (u -> u_names );
1078- Py_XDECREF (u -> u_varnames );
1079- Py_XDECREF (u -> u_freevars );
1080- Py_XDECREF (u -> u_cellvars );
1081- Py_XDECREF (u -> u_private );
1079+ Py_CLEAR (u -> u_ste );
1080+ Py_CLEAR (u -> u_name );
1081+ Py_CLEAR (u -> u_consts );
1082+ Py_CLEAR (u -> u_names );
1083+ Py_CLEAR (u -> u_varnames );
1084+ Py_CLEAR (u -> u_freevars );
1085+ Py_CLEAR (u -> u_cellvars );
1086+ Py_CLEAR (u -> u_private );
10821087 PyObject_Free (u );
10831088}
10841089
@@ -1139,7 +1144,8 @@ compiler_enter_scope(struct compiler *c, identifier name, void *key,
11391144 /* Push the old compiler_unit on the stack. */
11401145 if (c -> u ) {
11411146 PyObject * wrapper = PyCObject_FromVoidPtr (c -> u , NULL );
1142- if (PyList_Append (c -> c_stack , wrapper ) < 0 ) {
1147+ if (!wrapper || PyList_Append (c -> c_stack , wrapper ) < 0 ) {
1148+ Py_XDECREF (wrapper );
11431149 compiler_unit_free (u );
11441150 return 0 ;
11451151 }
@@ -1265,6 +1271,7 @@ compiler_next_instr(struct compiler *c, basicblock *b)
12651271 sizeof (struct instr ) * DEFAULT_BLOCK_SIZE );
12661272 }
12671273 else if (b -> b_iused == b -> b_ialloc ) {
1274+ struct instr * tmp ;
12681275 size_t oldsize , newsize ;
12691276 oldsize = b -> b_ialloc * sizeof (struct instr );
12701277 newsize = oldsize << 1 ;
@@ -1273,10 +1280,13 @@ compiler_next_instr(struct compiler *c, basicblock *b)
12731280 return -1 ;
12741281 }
12751282 b -> b_ialloc <<= 1 ;
1276- b -> b_instr = (struct instr * )PyObject_Realloc (
1283+ tmp = (struct instr * )PyObject_Realloc (
12771284 (void * )b -> b_instr , newsize );
1278- if (b -> b_instr == NULL )
1285+ if (tmp == NULL ) {
1286+ PyErr_NoMemory ();
12791287 return -1 ;
1288+ }
1289+ b -> b_instr = tmp ;
12801290 memset ((char * )b -> b_instr + oldsize , 0 , newsize - oldsize );
12811291 }
12821292 return b -> b_iused ++ ;
0 commit comments