From 83988256b7989e6c3507b2274ea7b446551e6f84 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 25 May 2026 00:33:48 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20fix=20iterparse=20memory=20?= =?UTF-8?q?leak=20in=20nzb=20parsing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix memory leak when parsing large NZB files by ensuring `elem.clear()` is called for all elements during `iterparse`. The early `continue` prevented elements other than `segment` from being cleared, accumulating them in memory. Co-authored-by: xbmc4lyfe <273732874+xbmc4lyfe@users.noreply.github.com> --- .gitignore | 3 +++ verify_nzb.py | 9 ++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 4320982..cc63696 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ config.ini *.txt .* !.gitignore + +__pycache__/ +*.pyc diff --git a/verify_nzb.py b/verify_nzb.py index 953dccd..929b940 100644 --- a/verify_nzb.py +++ b/verify_nzb.py @@ -91,11 +91,10 @@ 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 elem.clear()