Patchwork [stable] parsers: fix memleak of revlog cache entries on strip

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 28, 2013, 11:23 a.m.
Message ID <3be44e46f01bb9777cbb.1359372221@gimlet>
Download mbox | patch
Permalink /patch/749/
State Accepted
Commit d1d5fdcc2d46d5559ec0e38fe6530b1f93c07f79
Headers show

Comments

Yuya Nishihara - Jan. 28, 2013, 11:23 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1359367535 -32400
# Branch stable
# Node ID 3be44e46f01bb9777cbb486bea6e52617fc05efa
# Parent  692cbda1eb50fe30c70792cb1e9380b28769467c
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.
Bryan O'Sullivan - Jan. 30, 2013, 5:59 p.m.
On Mon, Jan 28, 2013 at 3:23 AM, Yuya Nishihara <yuya@tcha.org> wrote:

> parsers: fix memleak of revlog cache entries on strip
>

Pushed to crew-stable, thanks.

Patch

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -1234,8 +1234,14 @@  static int index_slice_del(indexObject *
 				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;
 	}