Skip to content

Commit 8452445

Browse files
authored
bpo-31247: xmlrpc.server: break reference cycle (#3166)
xmlrpc.server now explicitly breaks reference cycles when using sys.exc_info() in code handling exceptions.
1 parent f432a32 commit 8452445

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

Lib/xmlrpc/server.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,14 @@ def _marshaled_dispatch(self, data, dispatch_method = None, path = None):
270270
except:
271271
# report exception back to server
272272
exc_type, exc_value, exc_tb = sys.exc_info()
273-
response = dumps(
274-
Fault(1, "%s:%s" % (exc_type, exc_value)),
275-
encoding=self.encoding, allow_none=self.allow_none,
276-
)
273+
try:
274+
response = dumps(
275+
Fault(1, "%s:%s" % (exc_type, exc_value)),
276+
encoding=self.encoding, allow_none=self.allow_none,
277+
)
278+
finally:
279+
# Break reference cycle
280+
exc_type = exc_value = exc_tb = None
277281

278282
return response.encode(self.encoding, 'xmlcharrefreplace')
279283

@@ -365,10 +369,14 @@ def system_multicall(self, call_list):
365369
)
366370
except:
367371
exc_type, exc_value, exc_tb = sys.exc_info()
368-
results.append(
369-
{'faultCode' : 1,
370-
'faultString' : "%s:%s" % (exc_type, exc_value)}
371-
)
372+
try:
373+
results.append(
374+
{'faultCode' : 1,
375+
'faultString' : "%s:%s" % (exc_type, exc_value)}
376+
)
377+
finally:
378+
# Break reference cycle
379+
exc_type = exc_value = exc_tb = None
372380
return results
373381

374382
def _dispatch(self, method, params):
@@ -630,10 +638,14 @@ def _marshaled_dispatch(self, data, dispatch_method = None, path = None):
630638
# (each dispatcher should have handled their own
631639
# exceptions)
632640
exc_type, exc_value = sys.exc_info()[:2]
633-
response = dumps(
634-
Fault(1, "%s:%s" % (exc_type, exc_value)),
635-
encoding=self.encoding, allow_none=self.allow_none)
636-
response = response.encode(self.encoding, 'xmlcharrefreplace')
641+
try:
642+
response = dumps(
643+
Fault(1, "%s:%s" % (exc_type, exc_value)),
644+
encoding=self.encoding, allow_none=self.allow_none)
645+
response = response.encode(self.encoding, 'xmlcharrefreplace')
646+
finally:
647+
# Break reference cycle
648+
exc_type = exc_value = None
637649
return response
638650

639651
class CGIXMLRPCRequestHandler(SimpleXMLRPCDispatcher):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
xmlrpc.server now explicitly breaks reference cycles when using
2+
sys.exc_info() in code handling exceptions.

0 commit comments

Comments
 (0)