Patchwork [1,of,2] lock: clear postrelease hooks list after usage

login
register
mail settings
Submitter Gregory Szorc
Date April 16, 2016, 4:08 p.m.
Message ID <9acb28de651539bfb776.1460822919@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/14679/
State Accepted
Headers show

Comments

Gregory Szorc - April 16, 2016, 4:08 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1460822415 25200
#      Sat Apr 16 09:00:15 2016 -0700
# Node ID 9acb28de651539bfb776eba9e2a59bc8cb3a52f0
# Parent  d9539959167df7cb3acd08c4ab53d8e8a7f027cb
lock: clear postrelease hooks list after usage

Post release hooks should only be called once. Setting the
list to None after usage will prevent accidental usage after
they are used.

In addition, it is easy for reference cycles to sneak into hook
functions. Clearing the hooks after usage helps prevent these
cycles.

Patch

diff --git a/mercurial/lock.py b/mercurial/lock.py
--- a/mercurial/lock.py
+++ b/mercurial/lock.py
@@ -229,13 +229,15 @@  class lock(object):
                         self.vfs.unlink(self.f)
                     except OSError:
                         pass
             # The postrelease functions typically assume the lock is not held
             # at all.
             if not self._parentheld:
                 for callback in self.postrelease:
                     callback()
+                # Prevent double usage and help clear cycles.
+                self.postrelease = None
 
 def release(*locks):
     for lock in locks:
         if lock is not None:
             lock.release()