Mercurial > hg
view tests/test-context.py @ 24710:909ee6b2a024
lazymanifest: prevent leak when updating an entry more than once
__setitem__ on the lazymanifest C type wasn't checking to see if a
line had previously been malloced before replacing it, leading to
leaks if files got updated multiple times in the course of a task.
I was able to reproduce the leak with this change to test-manifest.py:
diff --git a/tests/test-manifest.py b/tests/test-manifest.py
--- a/tests/test-manifest.py
+++ b/tests/test-manifest.py
@@ -456,6 +456,16 @@ class basemanifesttests(object):
['a/b/c/bar.txt', 'a/b/c/foo.txt', 'a/b/d/ten.txt'],
m2.keys())
+ def testManifestSetItem(self):
+ m = self.parsemanifest('')
+ for x in range(3):
+ m['file%d' % x] = BIN_HASH_1
+ for x in range(3):
+ m['file%d' % x] = BIN_HASH_2
+ import time
+ time.sleep(4)
+
+
along with the commands:
$ make local
$ PYTHONPATH=. SILENT_BE_NOISY=1 python tests/test-manifest.py testmanifestdict.testManifestSetItem &
$ sleep 4
$ leaks $(jobs -p | tee /dev/stderr | awk '{print $3}')
$ wait
in an interactive shell on OS X. As far as I can tell, it had to be an
interactive shell so that I could get the pid of the test run using
the jobs builtin. Prior to this change, I was leaking several strings,
and after this change leaks reports no leaks.
I thought there was a bug filed for this in bugzilla, but I can't find
it either in bugzilla or by searching my email.
author | Augie Fackler <augie@google.com> |
---|---|
date | Sat, 11 Apr 2015 11:56:21 -0400 |
parents | d8e0c591781c |
children | 01489fa0bbbe |
line wrap: on
line source
import os from mercurial import hg, ui, context, encoding u = ui.ui() repo = hg.repository(u, 'test1', create=1) os.chdir('test1') # create 'foo' with fixed time stamp f = open('foo', 'wb') f.write('foo\n') f.close() os.utime('foo', (1000, 1000)) # add+commit 'foo' repo[None].add(['foo']) repo.commit(text='commit1', date="0 0") print "workingfilectx.date =", repo[None]['foo'].date() # test memctx with non-ASCII commit message def filectxfn(repo, memctx, path): return context.memfilectx(repo, "foo", "") ctx = context.memctx(repo, ['tip', None], encoding.tolocal("Gr\xc3\xbcezi!"), ["foo"], filectxfn) ctx.commit() for enc in "ASCII", "Latin-1", "UTF-8": encoding.encoding = enc print "%-8s: %s" % (enc, repo["tip"].description()) # test performing a status def getfilectx(repo, memctx, f): fctx = memctx.parents()[0][f] data, flags = fctx.data(), fctx.flags() if f == 'foo': data += 'bar\n' return context.memfilectx(repo, f, data, 'l' in flags, 'x' in flags) ctxa = repo.changectx(0) ctxb = context.memctx(repo, [ctxa.node(), None], "test diff", ["foo"], getfilectx, ctxa.user(), ctxa.date()) print ctxb.status(ctxa) # test performing a diff on a memctx for d in ctxb.diff(ctxa, git=True): print d # test safeness and correctness of "ctx.status()" print '= checking context.status():' # ancestor "wcctx ~ 2" actx2 = repo['.'] repo.wwrite('bar-m', 'bar-m\n', '') repo.wwrite('bar-r', 'bar-r\n', '') repo[None].add(['bar-m', 'bar-r']) repo.commit(text='add bar-m, bar-r', date="0 0") # ancestor "wcctx ~ 1" actx1 = repo['.'] repo.wwrite('bar-m', 'bar-m bar-m\n', '') repo.wwrite('bar-a', 'bar-a\n', '') repo[None].add(['bar-a']) repo[None].forget(['bar-r']) # status at this point: # M bar-m # A bar-a # R bar-r # C foo from mercurial import scmutil print '== checking workingctx.status:' wctx = repo[None] print 'wctx._status=%s' % (str(wctx._status)) print '=== with "pattern match":' print actx1.status(other=wctx, match=scmutil.matchfiles(repo, ['bar-m', 'foo'])) print 'wctx._status=%s' % (str(wctx._status)) print actx2.status(other=wctx, match=scmutil.matchfiles(repo, ['bar-m', 'foo'])) print 'wctx._status=%s' % (str(wctx._status)) print '=== with "always match" and "listclean=True":' print actx1.status(other=wctx, listclean=True) print 'wctx._status=%s' % (str(wctx._status)) print actx2.status(other=wctx, listclean=True) print 'wctx._status=%s' % (str(wctx._status)) print "== checking workingcommitctx.status:" wcctx = context.workingcommitctx(repo, scmutil.status(['bar-m'], ['bar-a'], [], [], [], [], []), text='', date='0 0') print 'wcctx._status=%s' % (str(wcctx._status)) print '=== with "always match":' print actx1.status(other=wcctx) print 'wcctx._status=%s' % (str(wcctx._status)) print actx2.status(other=wcctx) print 'wcctx._status=%s' % (str(wcctx._status)) print '=== with "always match" and "listclean=True":' print actx1.status(other=wcctx, listclean=True) print 'wcctx._status=%s' % (str(wcctx._status)) print actx2.status(other=wcctx, listclean=True) print 'wcctx._status=%s' % (str(wcctx._status)) print '=== with "pattern match":' print actx1.status(other=wcctx, match=scmutil.matchfiles(repo, ['bar-m', 'foo'])) print 'wcctx._status=%s' % (str(wcctx._status)) print actx2.status(other=wcctx, match=scmutil.matchfiles(repo, ['bar-m', 'foo'])) print 'wcctx._status=%s' % (str(wcctx._status)) print '=== with "pattern match" and "listclean=True":' print actx1.status(other=wcctx, match=scmutil.matchfiles(repo, ['bar-r', 'foo']), listclean=True) print 'wcctx._status=%s' % (str(wcctx._status)) print actx2.status(other=wcctx, match=scmutil.matchfiles(repo, ['bar-r', 'foo']), listclean=True) print 'wcctx._status=%s' % (str(wcctx._status))