diff mercurial/parsers.c @ 26016:c8d41c9c23c7

reachableroots: unify bail cases to raise exception correctly Before this patch, release_seen_and_tovisit did not return NULL, so the exception was not raised immediately. As Py_XDECREF() and free() are safe for NULL, we can simply bail in any case.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 13 Aug 2015 18:29:38 +0900
parents ed60d2ae1935
children 44705659da94
line wrap: on
line diff
--- a/mercurial/parsers.c	Thu Aug 13 17:58:33 2015 +0900
+++ b/mercurial/parsers.c	Thu Aug 13 18:29:38 2015 +0900
@@ -1154,13 +1154,13 @@
 	tovisit = (int *)malloc((len + 1) * sizeof(int));
 	if (tovisit == NULL) {
 		PyErr_NoMemory();
-		goto release_reachable;
+		goto bail;
 	}
 
 	seen = (char *)calloc(len+1, 1);
 	if (seen == NULL) {
 		PyErr_NoMemory();
-		goto release_seen_and_tovisit;
+		goto bail;
 	}
 
 	/* Populate tovisit with all the heads */
@@ -1192,7 +1192,7 @@
 		if (revnum != -1) {
 			r = index_get_parents(self, revnum, parents, (int)len - 1);
 			if (r < 0)
-				goto release_seen_and_tovisit;
+				goto bail;
 
 			for (i = 0; i < 2; i++) {
 				if (seen[parents[i] + 1] == 0 && parents[i] >= minroot) {
@@ -1214,7 +1214,7 @@
 				r = index_get_parents(self, i, parents, (int)len - 1);
 				/* Corrupted index file, error is set from index_get_parents */
 				if (r < 0)
-					goto release_seen_and_tovisit;
+					goto bail;
 				for (k = 0; k < 2; k++) {
 					PyObject *p = PyInt_FromLong(parents[k]);
 					if (PySet_Contains(reachable, p) == 1)
@@ -1225,13 +1225,13 @@
 		}
 	}
 
-release_seen_and_tovisit:
 	free(seen);
 	free(tovisit);
 	return reachable;
-release_reachable:
+bail:
 	Py_XDECREF(reachable);
-bail:
+	free(seen);
+	free(tovisit);
 	return NULL;
 }