Patchwork D4154: index: remove side-effect from failed nt_new()

login
register
mail settings
Submitter phabricator
Date Aug. 7, 2018, 12:52 p.m.
Message ID <1beee9ceb09a2a0ea5dcd8d8962081ab@localhost.localdomain>
Download mbox | patch
Permalink /patch/33393/
State Not Applicable
Headers show

Comments

phabricator - Aug. 7, 2018, 12:52 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGdcd395dc98d8: index: remove side-effect from failed nt_new() (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4154?vs=10035&id=10049

REVISION DETAIL
  https://phab.mercurial-scm.org/D4154

AFFECTED FILES
  mercurial/cext/revlog.c

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -1018,18 +1018,21 @@ 
 static int nt_new(nodetree *self)
 {
 	if (self->length == self->capacity) {
+		unsigned newcapacity;
+		nodetreenode *newnodes;
 		if (self->capacity >= INT_MAX / (sizeof(nodetreenode) * 2)) {
 			PyErr_SetString(PyExc_MemoryError,
 					"overflow in nt_new");
 			return -1;
 		}
-		self->capacity *= 2;
-		self->nodes = realloc(self->nodes,
-		                      self->capacity * sizeof(nodetreenode));
-		if (self->nodes == NULL) {
+		newcapacity = self->capacity * 2;
+		newnodes = realloc(self->nodes, newcapacity * sizeof(nodetreenode));
+		if (newnodes == NULL) {
 			PyErr_SetString(PyExc_MemoryError, "out of memory");
 			return -1;
 		}
+		self->capacity = newcapacity;
+		self->nodes = newnodes;
 		memset(&self->nodes[self->length], 0,
 		       sizeof(nodetreenode) * (self->capacity - self->length));
 	}