From 10cc3adf1d6ee66be80fc9a5d6484fbb0cafbc44 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 23 May 2026 00:09:52 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Fix=20O(N)=20memory=20leak?= =?UTF-8?q?=20in=20NZB=20parsing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified `parse_nzb_message_ids` in `verify_nzb.py` to ensure `elem.clear()` is called for all elements during `ET.iterparse`, not just `` elements. This prevents the entire XML DOM tree from accumulating in memory for large NZB files. Co-authored-by: xbmc4lyfe <273732874+xbmc4lyfe@users.noreply.github.com> --- verify_nzb.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/verify_nzb.py b/verify_nzb.py index 953dccd..55fc6d5 100644 --- a/verify_nzb.py +++ b/verify_nzb.py @@ -91,11 +91,11 @@ def parse_nzb_message_ids(path: str | Path) -> Iterator[str]: with open(path, "rb") as handle: for event, elem in ET.iterparse(handle, events=("end",)): - if _local_name(elem.tag) != "segment": - continue - text = (elem.text or "").strip() - if text: - yield text + if _local_name(elem.tag) == "segment": + text = (elem.text or "").strip() + if text: + yield text + # Always clear the element to prevent memory leaks from building the entire DOM tree elem.clear()