[PATCH 3 of 3 in crew] parsers: correctly handle a failed allocation

Bryan O'Sullivan bos at serpentine.com
Mon Sep 16 14:27:32 CDT 2013


# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1379359075 25200
#      Mon Sep 16 12:17:55 2013 -0700
# Node ID 3d07b4a2f7438cc54e8771d4db14dd1cd4b69fee
# Parent  b3c8c6f2b5c146c9d3464058ff40d031a97b371d
parsers: correctly handle a failed allocation

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -1212,14 +1212,19 @@ static PyObject *find_gca_candidates(ind
 	long sp;
 	bitmask *seen;
 
+	if (gca == NULL)
+		return PyErr_NoMemory();
+
 	for (i = 0; i < revcount; i++) {
 		if (revs[i] > maxrev)
 			maxrev = revs[i];
 	}
 
 	seen = calloc(sizeof(*seen), maxrev + 1);
-	if (seen == NULL)
+	if (seen == NULL) {
+		Py_DECREF(gca);
 		return PyErr_NoMemory();
+	}
 
 	for (i = 0; i < revcount; i++)
 		seen[revs[i]] = 1ull << i;


More information about the Mercurial-devel mailing list