# HG changeset patch # User Mads Kiilerich # Date 2011-10-13 02:27:49 # Node ID 7b15dd9125b301a1b9e1d642268df0f2fd04e4d4 # Parent aa2c35057f47c3ec9ee6470c771b6a45a9784c22 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. diff --git a/mercurial/httprepo.py b/mercurial/httprepo.py --- a/mercurial/httprepo.py +++ b/mercurial/httprepo.py @@ -28,6 +28,7 @@ class httprepository(wireproto.wirerepos 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 @@ class httprepository(wireproto.wirerepos 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 diff --git a/tests/test-url-rev.t b/tests/test-url-rev.t --- a/tests/test-url-rev.t +++ b/tests/test-url-rev.t @@ -200,4 +200,8 @@ Pull -u takes us back to branch foo: 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]