fix memory leak and null pointer dereference
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 1829c3d..ef3f332 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -552,7 +552,9 @@
 		}
 	} /* for j, k */
 	
-	if (a != NULL) {
+	if (a == NULL)
+		*prem = NULL;
+	else {
 		a = long_normalize(a);
 		*prem = divrem1(v, d, &d);
 		/* d receives the (unused) remainder */
@@ -1001,7 +1003,7 @@
 				break;
 			}
 		}
-		if (a == NULL)
+		if (a == NULL || z == NULL)
 			break;
 	}
 	XDECREF(a);