index: use PyMem_Free() to free nodeetree instance
authorMartin von Zweigbergk <martinvonz@google.com>
Mon, 06 Aug 2018 22:24:34 -0700
changeset 38936 05c1f5f49ebb
parent 38935 27a54096c92e
child 38937 f7d8fb2ed8a8
index: use PyMem_Free() to free nodeetree instance As Yuya pointed out in the review of 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. Differential Revision: https://phab.mercurial-scm.org/D4152
mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c	Mon Aug 06 22:24:00 2018 -0700
+++ b/mercurial/cext/revlog.c	Mon Aug 06 22:24:34 2018 -0700
@@ -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;
 		}