Merge lp:~jelmer/brz/leaks into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/leaks
Merge into: lp:brz
Diff against target: 324 lines (+43/-76)
13 files modified
breezy/bzr/smart/server.py (+6/-8)
breezy/bzr/tests/test_smart_transport.py (+2/-2)
breezy/tests/blackbox/test_init.py (+0/-1)
breezy/tests/https_server.py (+6/-4)
breezy/tests/test_cethread.py (+2/-2)
breezy/tests/test_https_urllib.py (+0/-38)
breezy/transport/__init__.py (+4/-3)
breezy/transport/local.py (+5/-5)
breezy/transport/readonly.py (+1/-1)
breezy/transport/remote.py (+2/-2)
breezy/transport/sftp.py (+1/-1)
breezy/transport/trace.py (+8/-7)
breezy/workingtree.py (+6/-2)
To merge this branch: bzr merge lp:~jelmer/brz/leaks
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+421165@code.launchpad.net

Commit message

Fix some leaks.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/bzr/smart/server.py'
2--- breezy/bzr/smart/server.py 2020-06-10 23:47:24 +0000
3+++ breezy/bzr/smart/server.py 2022-05-03 12:58:14 +0000
4@@ -277,19 +277,17 @@
5 thread_name = 'smart-server-child' + thread_name_suffix
6 handler = self._make_handler(conn)
7 connection_thread = threading.Thread(
8- None, handler.serve, name=thread_name)
9+ None, handler.serve, name=thread_name, daemon=True)
10 self._active_connections.append((handler, connection_thread))
11- connection_thread.setDaemon(True)
12 connection_thread.start()
13 return connection_thread
14
15 def start_background_thread(self, thread_name_suffix=''):
16 self._started.clear()
17- self._server_thread = threading.Thread(None,
18- self.serve, args=(
19- thread_name_suffix,),
20- name='server-' + self.get_url())
21- self._server_thread.setDaemon(True)
22+ self._server_thread = threading.Thread(
23+ None, self.serve, args=(thread_name_suffix,),
24+ name='server-' + self.get_url(),
25+ daemon=True)
26 self._server_thread.start()
27 self._started.wait()
28
29@@ -307,7 +305,7 @@
30 except self._socket_error:
31 # ignore errors on close
32 pass
33- if not self._stopped.isSet():
34+ if not self._stopped.is_set():
35 # server has not stopped (though it may be stopping)
36 # its likely in accept(), so give it a connection
37 temp_socket = socket.socket()
38
39=== modified file 'breezy/bzr/tests/test_smart_transport.py'
40--- breezy/bzr/tests/test_smart_transport.py 2021-01-10 00:25:52 +0000
41+++ breezy/bzr/tests/test_smart_transport.py 2022-05-03 12:58:14 +0000
42@@ -1320,7 +1320,7 @@
43 # don't need to try to connect to it. Not being set, though, the server
44 # might still close the socket while we try to connect to it. So we
45 # still have to catch the exception.
46- if server._stopped.isSet():
47+ if server._stopped.is_set():
48 return
49 try:
50 client_sock = self.connect_to_server(server)
51@@ -1470,7 +1470,7 @@
52 client_sock.close()
53 server_side_thread.join()
54 server_thread.join()
55- self.assertTrue(server._fully_stopped.isSet())
56+ self.assertTrue(server._fully_stopped.is_set())
57 log = self.get_log()
58 self.assertThat(log, DocTestMatches("""\
59 INFO Requested to stop gracefully
60
61=== modified file 'breezy/tests/blackbox/test_init.py'
62--- breezy/tests/blackbox/test_init.py 2021-11-15 17:27:44 +0000
63+++ breezy/tests/blackbox/test_init.py 2022-05-03 12:58:14 +0000
64@@ -199,7 +199,6 @@
65 out, err = self.run_bzr(['init', '--format=pack-0.92', self.get_url()])
66 self.assertEqual(out,
67 """Created a standalone branch (format: pack-0.92)\n""")
68- self.assertEqual('', err)
69
70 def test_init_existing_branch(self):
71 # when there is already a branch present, make mention
72
73=== modified file 'breezy/tests/https_server.py'
74--- breezy/tests/https_server.py 2018-11-12 01:41:38 +0000
75+++ breezy/tests/https_server.py 2022-05-03 12:58:14 +0000
76@@ -33,10 +33,12 @@
77
78 def _get_ssl_request(self, sock, addr):
79 """Wrap the socket with SSL"""
80- ssl_sock = ssl.wrap_socket(sock, server_side=True,
81- keyfile=self.key_file,
82- certfile=self.cert_file,
83- do_handshake_on_connect=False)
84+ ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
85+ if self.cert_file:
86+ ssl_context.load_cert_chain(self.cert_file, self.key_file)
87+ ssl_sock = ssl_context.wrap_socket(
88+ sock=sock, server_side=True,
89+ do_handshake_on_connect=False)
90 return ssl_sock, addr
91
92 def verify_request(self, request, client_address):
93
94=== modified file 'breezy/tests/test_cethread.py'
95--- breezy/tests/test_cethread.py 2018-11-11 04:08:32 +0000
96+++ breezy/tests/test_cethread.py 2022-05-03 12:58:14 +0000
97@@ -83,7 +83,7 @@
98 self.assertIs(in_thread, tt.sync_event)
99 control.set()
100 self.assertRaises(MyException, tt.join)
101- self.assertEqual(True, tt.sync_event.isSet())
102+ self.assertEqual(True, tt.sync_event.is_set())
103
104 def test_switch_and_set(self):
105 """Caller can precisely control a thread."""
106@@ -160,4 +160,4 @@
107 tt.step1.wait()
108 self.assertRaises(MyException, tt.pending_exception)
109 self.assertIs(tt.step1, tt.sync_event)
110- self.assertTrue(tt.step1.isSet())
111+ self.assertTrue(tt.step1.is_set())
112
113=== modified file 'breezy/tests/test_https_urllib.py'
114--- breezy/tests/test_https_urllib.py 2020-02-07 02:14:30 +0000
115+++ breezy/tests/test_https_urllib.py 2022-05-03 12:58:14 +0000
116@@ -75,41 +75,3 @@
117 stack = config.MemoryStack(b"ssl.cert_reqs = invalid\n")
118 self.assertRaises(config.ConfigOptionValueError, stack.get,
119 "ssl.cert_reqs")
120-
121-
122-class MatchHostnameTests(tests.TestCase):
123-
124- def test_no_certificate(self):
125- self.assertRaises(ValueError,
126- ssl.match_hostname, {}, "example.com")
127-
128- def test_wildcards_in_cert(self):
129- def ok(cert, hostname):
130- ssl.match_hostname(cert, hostname)
131-
132- def not_ok(cert, hostname):
133- self.assertRaises(
134- ssl.CertificateError,
135- ssl.match_hostname, cert, hostname)
136-
137- # Python Issue #17980: avoid denials of service by refusing more than
138- # one wildcard per fragment.
139- if sys.version_info[:2] >= (3, 7):
140- # Python 3.7 dropped support for partial wildcards, see
141- # https://docs.python.org/3/whatsnew/3.7.html#ssl
142- not_ok({'subject': ((('commonName', 'a*b.com'),),)}, 'axxb.com')
143- else:
144- ok({'subject': ((('commonName', 'a*b.com'),),)}, 'axxb.com')
145- not_ok({'subject': ((('commonName', 'a*b.co*'),),)}, 'axxb.com')
146- not_ok({'subject': ((('commonName', 'a*b*.com'),),)}, 'axxbxxc.com')
147-
148- def test_no_valid_attributes(self):
149- self.assertRaises(ssl.CertificateError, ssl.match_hostname,
150- {"Problem": "Solved"}, "example.com")
151-
152- def test_common_name(self):
153- cert = {'subject': ((('commonName', 'example.com'),),)}
154- self.assertIs(None,
155- ssl.match_hostname(cert, "example.com"))
156- self.assertRaises(ssl.CertificateError, ssl.match_hostname,
157- cert, "example.org")
158
159=== modified file 'breezy/transport/__init__.py'
160--- breezy/transport/__init__.py 2021-01-10 00:25:52 +0000
161+++ breezy/transport/__init__.py 2022-05-03 12:58:14 +0000
162@@ -860,7 +860,7 @@
163 coalesced_offsets.append(cur)
164 return coalesced_offsets
165
166- def put_bytes(self, relpath, raw_bytes, mode=None):
167+ def put_bytes(self, relpath: str, raw_bytes: bytes, mode=None):
168 """Atomically put the supplied bytes into the given location.
169
170 :param relpath: The location to put the contents, relative to the
171@@ -874,7 +874,7 @@
172 'raw_bytes must be a plain string, not %s' % type(raw_bytes))
173 return self.put_file(relpath, BytesIO(raw_bytes), mode=mode)
174
175- def put_bytes_non_atomic(self, relpath, raw_bytes, mode=None,
176+ def put_bytes_non_atomic(self, relpath, raw_bytes: bytes, mode=None,
177 create_parent_dir=False,
178 dir_mode=None):
179 """Copy the string into the target location.
180@@ -998,7 +998,8 @@
181 Override this for efficiency if a specific transport can do it
182 faster than this default implementation.
183 """
184- self.put_file(rel_to, self.get(rel_from))
185+ with self.get(rel_from) as f:
186+ self.put_file(rel_to, f)
187
188 def copy_to(self, relpaths, other, mode=None, pb=None):
189 """Copy a set of entries from self into another Transport.
190
191=== modified file 'breezy/transport/local.py'
192--- breezy/transport/local.py 2022-01-12 23:43:40 +0000
193+++ breezy/transport/local.py 2022-05-03 12:58:14 +0000
194@@ -181,7 +181,7 @@
195 fp.close()
196 return length
197
198- def put_bytes(self, relpath, raw_bytes, mode=None):
199+ def put_bytes(self, relpath: str, raw_bytes: bytes, mode=None):
200 """Copy the string into the location.
201
202 :param relpath: Location to put the contents, relative to base.
203@@ -198,7 +198,7 @@
204 except (IOError, OSError) as e:
205 self._translate_error(e, path)
206 try:
207- if bytes:
208+ if raw_bytes:
209 fp.write(raw_bytes)
210 fp.commit()
211 finally:
212@@ -277,11 +277,11 @@
213 create_parent_dir=create_parent_dir,
214 dir_mode=dir_mode)
215
216- def put_bytes_non_atomic(self, relpath, bytes, mode=None,
217+ def put_bytes_non_atomic(self, relpath: str, raw_bytes: bytes, mode=None,
218 create_parent_dir=False, dir_mode=None):
219 def writer(fd):
220- if bytes:
221- os.write(fd, bytes)
222+ if raw_bytes:
223+ os.write(fd, raw_bytes)
224 self._put_non_atomic_helper(relpath, writer, mode=mode,
225 create_parent_dir=create_parent_dir,
226 dir_mode=dir_mode)
227
228=== modified file 'breezy/transport/readonly.py'
229--- breezy/transport/readonly.py 2020-02-18 01:57:45 +0000
230+++ breezy/transport/readonly.py 2022-05-03 12:58:14 +0000
231@@ -55,7 +55,7 @@
232 """See Transport.put_file()."""
233 raise TransportNotPossible('readonly transport')
234
235- def put_bytes(self, relpath, bytes, mode=None):
236+ def put_bytes(self, relpath: str, raw_bytes: bytes, mode=None):
237 """See Transport.put_bytes()."""
238 raise TransportNotPossible('readonly transport')
239
240
241=== modified file 'breezy/transport/remote.py'
242--- breezy/transport/remote.py 2020-02-18 01:57:45 +0000
243+++ breezy/transport/remote.py 2022-05-03 12:58:14 +0000
244@@ -251,7 +251,7 @@
245 transport._file_streams[self.abspath(relpath)] = result
246 return result
247
248- def put_bytes(self, relpath, raw_bytes, mode=None):
249+ def put_bytes(self, relpath: str, raw_bytes: bytes, mode=None):
250 if not isinstance(raw_bytes, bytes):
251 raise TypeError(
252 'raw_bytes must be bytes string, not %s' % type(raw_bytes))
253@@ -262,7 +262,7 @@
254 self._ensure_ok(resp)
255 return len(raw_bytes)
256
257- def put_bytes_non_atomic(self, relpath, raw_bytes, mode=None,
258+ def put_bytes_non_atomic(self, relpath: str, raw_bytes: bytes, mode=None,
259 create_parent_dir=False,
260 dir_mode=None):
261 """See Transport.put_bytes_non_atomic."""
262
263=== modified file 'breezy/transport/sftp.py'
264--- breezy/transport/sftp.py 2020-02-18 01:57:45 +0000
265+++ breezy/transport/sftp.py 2022-05-03 12:58:14 +0000
266@@ -626,7 +626,7 @@
267 create_parent_dir=create_parent_dir,
268 dir_mode=dir_mode)
269
270- def put_bytes_non_atomic(self, relpath, raw_bytes, mode=None,
271+ def put_bytes_non_atomic(self, relpath: str, raw_bytes: bytes, mode=None,
272 create_parent_dir=False,
273 dir_mode=None):
274 if not isinstance(raw_bytes, bytes):
275
276=== modified file 'breezy/transport/trace.py'
277--- breezy/transport/trace.py 2020-02-18 01:57:45 +0000
278+++ breezy/transport/trace.py 2022-05-03 12:58:14 +0000
279@@ -102,18 +102,19 @@
280 """See Transport.put_file()."""
281 return self._decorated.put_file(relpath, f, mode)
282
283- def put_bytes(self, relpath, bytes, mode=None):
284+ def put_bytes(self, relpath: str, raw_bytes: bytes, mode=None):
285 """See Transport.put_bytes()."""
286- self._trace(('put_bytes', relpath, len(bytes), mode))
287- return self._decorated.put_bytes(relpath, bytes, mode)
288+ self._trace(('put_bytes', relpath, len(raw_bytes), mode))
289+ return self._decorated.put_bytes(relpath, raw_bytes, mode)
290
291- def put_bytes_non_atomic(self, relpath, bytes, mode=None,
292+ def put_bytes_non_atomic(self, relpath: str, raw_bytes: bytes, mode=None,
293 create_parent_dir=False, dir_mode=None):
294 """See Transport.put_bytes_non_atomic."""
295- self._trace(('put_bytes_non_atomic', relpath, len(bytes), mode,
296+ self._trace(('put_bytes_non_atomic', relpath, len(raw_bytes), mode,
297 create_parent_dir, dir_mode))
298- return self._decorated.put_bytes_non_atomic(relpath, bytes, mode=mode,
299- create_parent_dir=create_parent_dir, dir_mode=dir_mode)
300+ return self._decorated.put_bytes_non_atomic(
301+ relpath, raw_bytes, mode=mode, create_parent_dir=create_parent_dir,
302+ dir_mode=dir_mode)
303
304 def listable(self):
305 """See Transport.listable."""
306
307=== modified file 'breezy/workingtree.py'
308--- breezy/workingtree.py 2020-11-18 02:15:43 +0000
309+++ breezy/workingtree.py 2022-05-03 12:58:14 +0000
310@@ -367,8 +367,12 @@
311 if filtered and self.supports_content_filtering():
312 filters = self._content_filter_stack(path)
313 if filters:
314- file_obj, size = _mod_filters.filtered_input_file(
315- file_obj, filters)
316+ orig_file_obj = file_obj
317+ try:
318+ file_obj, size = _mod_filters.filtered_input_file(
319+ file_obj, filters)
320+ finally:
321+ orig_file_obj.close()
322 stat_value = _mod_filters.FilteredStat(
323 stat_value, st_size=size)
324 return (file_obj, stat_value)

Subscribers

People subscribed via source and target branches