httprepo: make __del__ more stable in error situations
authorMads Kiilerich <mads@kiilerich.com>
Thu, 13 Oct 2011 04:27:49 +0200
changeset 15246 7b15dd9125b3
parent 15245 aa2c35057f47
child 15247 3cd1605e9d8e
httprepo: make __del__ more stable in error situations Some errors could leave self.urlopener uninitialized and thus cause strange crashes in __del__. This member variable is now "declared statically" and checked for assignment before use.
mercurial/httprepo.py
tests/test-url-rev.t
--- a/mercurial/httprepo.py	Sun Oct 31 18:29:55 2010 +0100
+++ b/mercurial/httprepo.py	Thu Oct 13 04:27:49 2011 +0200
@@ -28,6 +28,7 @@
         self.path = path
         self.caps = None
         self.handler = None
+        self.urlopener = None
         u = util.url(path)
         if u.query or u.fragment:
             raise util.Abort(_('unsupported URL component: "%s"') %
@@ -42,9 +43,10 @@
         self.urlopener = url.opener(ui, authinfo)
 
     def __del__(self):
-        for h in self.urlopener.handlers:
-            h.close()
-            getattr(h, "close_all", lambda : None)()
+        if self.urlopener:
+            for h in self.urlopener.handlers:
+                h.close()
+                getattr(h, "close_all", lambda : None)()
 
     def url(self):
         return self.path
--- a/tests/test-url-rev.t	Sun Oct 31 18:29:55 2010 +0100
+++ b/tests/test-url-rev.t	Thu Oct 13 04:27:49 2011 +0200
@@ -200,4 +200,8 @@
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     new head of branch foo
   
+Test handling of invalid urls
 
+  $ hg id http://foo/?bar
+  abort: unsupported URL component: "bar"
+  [255]