Rev 5917: (jameinel) Delete local 'exc_info' variables when they go out of scope, in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu May 26 08:47:47 UTC 2011


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5917 [merge]
revision-id: pqm at pqm.ubuntu.com-20110526084744-2bim0fu54g836qd2
parent: pqm at pqm.ubuntu.com-20110526074901-tz91yfnl7a8ggkvk
parent: john at arbash-meinel.com-20110526080545-5tprxfczyj4bfk0o
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2011-05-26 08:47:44 +0000
message:
  (jameinel) Delete local 'exc_info' variables when they go out of scope,
   to avoid cycles with the exception tracebacks. (John A Meinel)
modified:
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/cleanup.py              cleanup.py-20090922032110-mv6i6y8t04oon9np-1
  bzrlib/decorators.py           decorators.py-20060112082512-6bfc2d882df1698d
  bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
  bzrlib/tests/test_errors.py    test_errors.py-20060210110251-41aba2deddf936a8
  bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2011-05-24 19:21:18 +0000
+++ b/bzrlib/branch.py	2011-05-26 08:05:45 +0000
@@ -3195,7 +3195,10 @@
         try:
             target.unlock()
         finally:
-            raise exc_info[0], exc_info[1], exc_info[2]
+            try:
+                raise exc_info[0], exc_info[1], exc_info[2]
+            finally:
+                del exc_info
     else:
         target.unlock()
         return result

=== modified file 'bzrlib/cleanup.py'
--- a/bzrlib/cleanup.py	2011-05-24 19:21:18 +0000
+++ b/bzrlib/cleanup.py	2011-05-26 08:05:45 +0000
@@ -188,7 +188,10 @@
                 # but don't propagate them.
                 _run_cleanup(cleanup, *c_args, **kwargs)
         if exc_info is not None:
-            raise exc_info[0], exc_info[1], exc_info[2]
+            try:
+                raise exc_info[0], exc_info[1], exc_info[2]
+            finally:
+                del exc_info
         # No error, so we can return the result
         return result
 

=== modified file 'bzrlib/decorators.py'
--- a/bzrlib/decorators.py	2011-05-24 19:21:18 +0000
+++ b/bzrlib/decorators.py	2011-05-26 08:05:45 +0000
@@ -109,7 +109,10 @@
         try:
             self.unlock()
         finally:
-            raise exc_info[0], exc_info[1], exc_info[2]
+            try:
+                raise exc_info[0], exc_info[1], exc_info[2]
+            finally:
+                del exc_info
     else:
         self.unlock()
         return result
@@ -155,7 +158,10 @@
             try:
                 self.unlock()
             finally:
-                raise exc_info[0], exc_info[1], exc_info[2]
+                try:
+                    raise exc_info[0], exc_info[1], exc_info[2]
+                finally:
+                    del exc_info
         else:
             self.unlock()
             return result
@@ -177,7 +183,10 @@
         try:
             self.unlock()
         finally:
-            raise exc_info[0], exc_info[1], exc_info[2]
+            try:
+                raise exc_info[0], exc_info[1], exc_info[2]
+            finally:
+                del exc_info
     else:
         self.unlock()
         return result
@@ -211,7 +220,10 @@
             try:
                 self.unlock()
             finally:
-                raise exc_info[0], exc_info[1], exc_info[2]
+                try:
+                    raise exc_info[0], exc_info[1], exc_info[2]
+                finally:
+                    del exc_info
         else:
             self.unlock()
             return result

=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2011-05-24 19:21:18 +0000
+++ b/bzrlib/osutils.py	2011-05-26 08:05:45 +0000
@@ -261,7 +261,10 @@
             else:
                 rename_func(tmp_name, new)
     if failure_exc is not None:
-        raise failure_exc[0], failure_exc[1], failure_exc[2]
+        try:
+            raise failure_exc[0], failure_exc[1], failure_exc[2]
+        finally:
+            del failure_exc
 
 
 # In Python 2.4.2 and older, os.path.abspath and os.path.realpath

=== modified file 'bzrlib/tests/test_errors.py'
--- a/bzrlib/tests/test_errors.py	2011-05-24 19:21:18 +0000
+++ b/bzrlib/tests/test_errors.py	2011-05-26 08:05:45 +0000
@@ -577,12 +577,17 @@
         try:
             1/0
         except ZeroDivisionError:
-            exc_info = sys.exc_info()
-        err = errors.HookFailed('hook stage', 'hook name', exc_info, warn=False)
-        self.assertStartsWith(
-            str(err), 'Hook \'hook name\' during hook stage failed:\n')
-        self.assertEndsWith(
-            str(err), 'integer division or modulo by zero')
+            err = errors.HookFailed('hook stage', 'hook name', sys.exc_info(),
+                warn=False)
+        # GZ 2010-11-08: Should not store exc_info in exception instances, but
+        #                HookFailed is deprecated anyway and could maybe go.
+        try:
+            self.assertStartsWith(
+                str(err), 'Hook \'hook name\' during hook stage failed:\n')
+            self.assertEndsWith(
+                str(err), 'integer division or modulo by zero')
+        finally:
+            del err
 
     def test_tip_change_rejected(self):
         err = errors.TipChangeRejected(u'Unicode message\N{INTERROBANG}')
@@ -611,11 +616,14 @@
         try:
             raise Exception("example error")
         except Exception:
-            exc_info = sys.exc_info()
-        err = errors.SmartMessageHandlerError(exc_info)
-        self.assertStartsWith(
-            str(err), "The message handler raised an exception:\n")
-        self.assertEndsWith(str(err), "Exception: example error\n")
+            err = errors.SmartMessageHandlerError(sys.exc_info())
+        # GZ 2010-11-08: Should not store exc_info in exception instances.
+        try:
+            self.assertStartsWith(
+                str(err), "The message handler raised an exception:\n")
+            self.assertEndsWith(str(err), "Exception: example error\n")
+        finally:
+            del err
 
     def test_must_have_working_tree(self):
         err = errors.MustHaveWorkingTree('foo', 'bar')

=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py	2011-05-24 19:21:18 +0000
+++ b/bzrlib/tests/test_knit.py	2011-05-26 08:05:45 +0000
@@ -444,6 +444,7 @@
         except _TestException, e:
             retry_exc = errors.RetryWithNewPacks(None, reload_occurred=False,
                                                  exc_info=sys.exc_info())
+        # GZ 2010-08-10: Cycle with exc_info affects 3 tests
         return retry_exc
 
     def test_read_from_several_packs(self):




More information about the bazaar-commits mailing list