parsers: fix memleak of revlog cache entries on strip stable
authorYuya Nishihara <yuya@tcha.org>
Mon, 28 Jan 2013 19:05:35 +0900
branchstable
changeset 18504 d1d5fdcc2d46
parent 18503 7f769d3a8ad2
child 18505 9de9727cea53
parsers: fix memleak of revlog cache entries on strip Since 12a852c7c763, raw_length can be reduced on strip, but corresponding cache entries still have refcount. They are not dereferenced by _index_clearcache(), and never freed. To reproduce the problem, run "hg pull" and "hg strip null" several times in the same process.
mercurial/parsers.c
--- a/mercurial/parsers.c	Wed Jan 30 17:32:17 2013 +0100
+++ b/mercurial/parsers.c	Mon Jan 28 19:05:35 2013 +0900
@@ -1234,8 +1234,14 @@
 				self->ntrev = (int)start;
 		}
 		self->length = start + 1;
-		if (start < self->raw_length)
+		if (start < self->raw_length) {
+			if (self->cache) {
+				Py_ssize_t i;
+				for (i = start; i < self->raw_length; i++)
+					Py_CLEAR(self->cache[i]);
+			}
 			self->raw_length = start;
+		}
 		goto done;
 	}