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

login
register
mail settings
Submitter Bryan O'Sullivan
Date Sept. 16, 2013, 7:27 p.m.
Message ID <3d07b4a2f7438cc54e87.1379359652@australite.local>
Download mbox | patch
Permalink /patch/2503/
State Accepted
Commit 3d07b4a2f7438cc54e8771d4db14dd1cd4b69fee
Headers show

Comments

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

Patch

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;