Fix more memory allocation issues found with failmalloc.
diff --git a/Python/compile.c b/Python/compile.c
index 3ee5cbb..564df18 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -300,8 +300,11 @@
 PyNode_Compile(struct _node *n, const char *filename)
 {
 	PyCodeObject *co = NULL;
+	mod_ty mod;
 	PyArena *arena = PyArena_New();
-	mod_ty mod = PyAST_FromNode(n, NULL, filename, arena);
+	if (!arena)
+		return NULL;
+	mod = PyAST_FromNode(n, NULL, filename, arena);
 	if (mod)
 		co = PyAST_Compile(mod, filename, NULL, arena);
 	PyArena_Free(arena);
@@ -615,8 +618,10 @@
 	unsigned int *blocks = (unsigned int *)PyMem_Malloc(len*sizeof(int));
 	int i,j, opcode, blockcnt = 0;
 
-	if (blocks == NULL)
+	if (blocks == NULL) {
+		PyErr_NoMemory();
 		return NULL;
+	}
 	memset(blocks, 0, len*sizeof(int));
 
 	/* Mark labels in the first pass */
@@ -1071,14 +1076,14 @@
 		PyObject_Free((void *)b);
 		b = next;
 	}
-	Py_XDECREF(u->u_ste);
-	Py_XDECREF(u->u_name);
-	Py_XDECREF(u->u_consts);
-	Py_XDECREF(u->u_names);
-	Py_XDECREF(u->u_varnames);
-	Py_XDECREF(u->u_freevars);
-	Py_XDECREF(u->u_cellvars);
-	Py_XDECREF(u->u_private);
+	Py_CLEAR(u->u_ste);
+	Py_CLEAR(u->u_name);
+	Py_CLEAR(u->u_consts);
+	Py_CLEAR(u->u_names);
+	Py_CLEAR(u->u_varnames);
+	Py_CLEAR(u->u_freevars);
+	Py_CLEAR(u->u_cellvars);
+	Py_CLEAR(u->u_private);
 	PyObject_Free(u);
 }
 
@@ -1139,7 +1144,8 @@
 	/* Push the old compiler_unit on the stack. */
 	if (c->u) {
 		PyObject *wrapper = PyCObject_FromVoidPtr(c->u, NULL);
-		if (PyList_Append(c->c_stack, wrapper) < 0) {
+		if (!wrapper || PyList_Append(c->c_stack, wrapper) < 0) {
+			Py_XDECREF(wrapper);
 			compiler_unit_free(u);
 			return 0;
 		}
@@ -1265,6 +1271,7 @@
 		       sizeof(struct instr) * DEFAULT_BLOCK_SIZE);
 	}
 	else if (b->b_iused == b->b_ialloc) {
+		struct instr *tmp;
 		size_t oldsize, newsize;
 		oldsize = b->b_ialloc * sizeof(struct instr);
 		newsize = oldsize << 1;
@@ -1273,10 +1280,13 @@
 			return -1;
 		}
 		b->b_ialloc <<= 1;
-		b->b_instr = (struct instr *)PyObject_Realloc(
+		tmp = (struct instr *)PyObject_Realloc(
                                                 (void *)b->b_instr, newsize);
-		if (b->b_instr == NULL)
+		if (tmp == NULL) {
+			PyErr_NoMemory();
 			return -1;
+		}
+		b->b_instr = tmp;
 		memset((char *)b->b_instr + oldsize, 0, newsize - oldsize);
 	}
 	return b->b_iused++;
diff --git a/Python/pyarena.c b/Python/pyarena.c
index f11a905..f4cc474 100644
--- a/Python/pyarena.c
+++ b/Python/pyarena.c
@@ -132,19 +132,19 @@
 {
 	PyArena* arena = (PyArena *)malloc(sizeof(PyArena));
 	if (!arena)
-		return NULL;
+		return (PyArena*)PyErr_NoMemory();
 
 	arena->a_head = block_new(DEFAULT_BLOCK_SIZE);
 	arena->a_cur = arena->a_head;
         if (!arena->a_head) {
                 free((void *)arena);
-                return NULL;
+                return (PyArena*)PyErr_NoMemory();
         }
         arena->a_objects = PyList_New(0);
         if (!arena->a_objects) {
                 block_free(arena->a_head);
                 free((void *)arena);
-                return NULL;
+                return (PyArena*)PyErr_NoMemory();
         }
 #if defined(Py_DEBUG)
         arena->total_allocs = 0;
@@ -191,7 +191,7 @@
 {
 	void *p = block_alloc(arena->a_cur, size);
 	if (!p)
-		return NULL;
+		return PyErr_NoMemory();
 #if defined(Py_DEBUG)
         arena->total_allocs++;
         arena->total_size += size;
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index bc83219..88fd67c 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -746,6 +746,11 @@
 			ps2 = PyString_AsString(w);
 	}
 	arena = PyArena_New();
+	if (arena == NULL) {
+		Py_XDECREF(v);
+		Py_XDECREF(w);
+		return -1;
+	}
 	mod = PyParser_ASTFromFile(fp, filename,
 				   Py_single_input, ps1, ps2,
 				   flags, &errcode, arena);
@@ -1203,9 +1208,8 @@
 		  PyObject *locals, PyCompilerFlags *flags)
 {
 	PyObject *ret = NULL;
-	PyArena *arena = PyArena_New();
 	mod_ty mod;
-
+	PyArena *arena = PyArena_New();
 	if (arena == NULL)
 		return NULL;
 	
@@ -1221,9 +1225,8 @@
 		  PyObject *locals, int closeit, PyCompilerFlags *flags)
 {
 	PyObject *ret;
-	PyArena *arena = PyArena_New();
 	mod_ty mod;
-
+	PyArena *arena = PyArena_New();
 	if (arena == NULL)
 		return NULL;
 	
@@ -1291,8 +1294,12 @@
 		      PyCompilerFlags *flags)
 {
 	PyCodeObject *co;
+	mod_ty mod;
 	PyArena *arena = PyArena_New();
-	mod_ty mod = PyParser_ASTFromString(str, filename, start, flags, arena);
+	if (arena == NULL)
+		return NULL;
+
+	mod = PyParser_ASTFromString(str, filename, start, flags, arena);
 	if (mod == NULL) {
 		PyArena_Free(arena);
 		return NULL;
@@ -1311,8 +1318,12 @@
 Py_SymtableString(const char *str, const char *filename, int start)
 {
 	struct symtable *st;
+	mod_ty mod;
 	PyArena *arena = PyArena_New();
-	mod_ty mod = PyParser_ASTFromString(str, filename, start, NULL, arena);
+	if (arena == NULL)
+		return NULL;
+
+	mod = PyParser_ASTFromString(str, filename, start, NULL, arena);
 	if (mod == NULL) {
 		PyArena_Free(arena);
 		return NULL;
diff --git a/Python/symtable.c b/Python/symtable.c
index fae9208..c010b7a 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -727,7 +727,7 @@
 {
 	Py_ssize_t end;
 
-	Py_DECREF(st->st_cur);
+	Py_CLEAR(st->st_cur);
 	end = PyList_GET_SIZE(st->st_stack) - 1;
 	if (end >= 0) {
 		st->st_cur = (PySTEntryObject *)PyList_GET_ITEM(st->st_stack,