D4152: index: use PyMem_Free() to free nodeetree instance

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Tue Aug 7 06:27:09 UTC 2018


martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  As Yuya pointed out in the review of https://phab.mercurial-scm.org/D4108, PyMem_Malloc() and
  PyMem_Free() should be paired. IIUC, PyMem_Malloc() may use a
  different allocator than malloc(), so using free() with a pointer from
  PyMem_Malloc() may be very wrong.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/cext/revlog.c

CHANGE DETAILS

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -323,7 +323,7 @@
 	}
 	if (self->nt != NULL) {
 		free(self->nt->nodes);
-		free(self->nt);
+		PyMem_Free(self->nt);
 	}
 	self->nt = NULL;
 	Py_CLEAR(self->headrevs);
@@ -1106,7 +1106,7 @@
 
 		self->nt->nodes = calloc(self->nt->capacity, sizeof(nodetreenode));
 		if (self->nt->nodes == NULL) {
-			free(self->nt);
+			PyMem_Free(self->nt);
 			self->nt = NULL;
 			PyErr_NoMemory();
 			return -1;
@@ -1119,7 +1119,7 @@
 		self->nt->length = 1;
 		if (nt_insert(self, nullid, -1) == -1) {
 			free(self->nt->nodes);
-			free(self->nt);
+			PyMem_Free(self->nt);
 			self->nt = NULL;
 			return -1;
 		}



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


More information about the Mercurial-devel mailing list