--- 2.7/urllib2.py 2011-09-26 12:02:11.922255665 +0200 +++ modified-2.7/urllib2.py 2011-10-08 20:56:56.000000000 +0200 @@ -395,7 +395,11 @@ meth_name = protocol+"_response" for processor in self.process_response.get(protocol, []): meth = getattr(processor, meth_name) - response = meth(req, response) + try: + response = meth(req, response) + except: + response.close() + raise return response @@ -1158,6 +1162,7 @@ except TypeError: #buffering kw not supported r = h.getresponse() except socket.error, err: # XXX what error? + h.close() raise URLError(err) # Pick apart the HTTPResponse object to get the addinfourl