Skip to content

Commit 702b046

Browse files
committed
python#27522: break unintended cycle in feedparser.
Patch by Costas.
1 parent 9305bba commit 702b046

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Lib/email/feedparser.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def __init__(self, _factory=None, *, policy=compat32):
145145
146146
"""
147147
self.policy = policy
148-
self._factory_kwds = lambda: {'policy': self.policy}
148+
self._old_style_factory = False
149149
if _factory is None:
150150
# What this should be:
151151
#self._factory = policy.default_message_factory
@@ -160,7 +160,7 @@ def __init__(self, _factory=None, *, policy=compat32):
160160
_factory(policy=self.policy)
161161
except TypeError:
162162
# Assume this is an old-style factory
163-
self._factory_kwds = lambda: {}
163+
self._old_style_factory = True
164164
self._input = BufferedSubFile()
165165
self._msgstack = []
166166
self._parse = self._parsegen().__next__
@@ -197,7 +197,10 @@ def close(self):
197197
return root
198198

199199
def _new_message(self):
200-
msg = self._factory(**self._factory_kwds())
200+
if self._old_style_factory:
201+
msg = self._factory()
202+
else:
203+
msg = self._factory(policy=self.policy)
201204
if self._cur and self._cur.get_content_type() == 'multipart/digest':
202205
msg.set_default_type('message/rfc822')
203206
if self._msgstack:

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Core and Builtins
2424
Library
2525
-------
2626

27+
- Issue #27522: Avoid an unintentional reference cycle in email.feedparser.
28+
2729
- Issue #26844: Fix error message for imp.find_module() to refer to 'path'
2830
instead of 'name'. Patch by Lev Maximov.
2931

0 commit comments

Comments
 (0)