From d286a8326a92cccbeccc0b998f3fb1e37353e510 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 18 May 2022 16:26:45 -0400 Subject: [PATCH] Clean up socket on deletion Some resources are leaked on deletion of a webclient without explicit close, improve by destructor. Change-Id: I91d313125bf79f83c3cd07e12e573b2bdd5a95ef --- pyghmi/util/webclient.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyghmi/util/webclient.py b/pyghmi/util/webclient.py index 6d7f2201..706ec60e 100644 --- a/pyghmi/util/webclient.py +++ b/pyghmi/util/webclient.py @@ -151,6 +151,11 @@ class SecureHTTPConnection(httplib.HTTPConnection, object): if '[' not in host and '%' in host and 'Host'not in self.stdheaders: self.stdheaders['Host'] = '[' + host[:host.find('%')] + ']' + def __del__(self): + if self.sock: + self.sock.close() + self.sock = None + def dupe(self): return SecureHTTPConnection(self.thehost, self.theport, clone=self, timeout=self.mytimeout)