From 7bfc4337afae0282cf30db889ba564425d642103 Mon Sep 17 00:00:00 2001 From: Charalampos Stratakis Date: Mon, 16 Feb 2026 18:58:48 +0100 Subject: [PATCH] Fix another memory leak Related: RHEL-120839 --- fix-memory-leak.patch | 23 ------------------- fix-memory-leaks.patch | 52 ++++++++++++++++++++++++++++++++++++++++++ python3.14-lxml.spec | 8 ++++--- 3 files changed, 57 insertions(+), 26 deletions(-) delete mode 100644 fix-memory-leak.patch create mode 100644 fix-memory-leaks.patch diff --git a/fix-memory-leak.patch b/fix-memory-leak.patch deleted file mode 100644 index 8deedd3..0000000 --- a/fix-memory-leak.patch +++ /dev/null @@ -1,23 +0,0 @@ -From b9de95a1caf39c5eee35c984fd0b51ddd1b0d40e Mon Sep 17 00:00:00 2001 -From: Stefan Behnel -Date: Sat, 17 Jan 2026 07:21:23 +0100 -Subject: [PATCH] Add missing "noexcept" to fix a memory leak. - -Fixes https://bugs.launchpad.net/lxml/+bug/2138421 ---- - src/lxml/etree.pyx | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lxml/etree.pyx b/src/lxml/etree.pyx -index 2ed3d1e15..3e7dca047 100644 ---- a/src/lxml/etree.pyx -+++ b/src/lxml/etree.pyx -@@ -668,7 +668,7 @@ cdef class DocInfo: - return root_name - - @cython.final -- cdef tree.xmlDtd* _get_c_dtd(self): -+ cdef tree.xmlDtd* _get_c_dtd(self) noexcept: - """"Return the DTD. Create it if it does not yet exist.""" - cdef xmlDoc* c_doc = self._doc._c_doc - cdef xmlNode* c_root_node diff --git a/fix-memory-leaks.patch b/fix-memory-leaks.patch new file mode 100644 index 0000000..958f052 --- /dev/null +++ b/fix-memory-leaks.patch @@ -0,0 +1,52 @@ +From 9abf22ef29816787256605a281e1413bd6063590 Mon Sep 17 00:00:00 2001 +From: Stefan Behnel +Date: Thu, 4 Dec 2025 11:50:30 +0100 +Subject: [PATCH 1/2] Fix a memory leak in the rare case of a memory allocation + error. + +--- + src/lxml/parser.pxi | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/src/lxml/parser.pxi b/src/lxml/parser.pxi +index 3106e61..8d53277 100644 +--- a/src/lxml/parser.pxi ++++ b/src/lxml/parser.pxi +@@ -2004,6 +2004,7 @@ cdef xmlDoc* _copyDocRoot(xmlDoc* c_doc, xmlNode* c_new_root) except NULL: + with nogil: + c_node = tree.xmlDocCopyNode(c_new_root, result, 1) # recursive + if c_node is NULL: ++ tree.xmlFreeDoc(result) + raise MemoryError() + tree.xmlDocSetRootElement(result, c_node) + _copyTail(c_new_root.next, c_node) +-- +2.53.0 + + +From 3f148c66c78cd7c010721e4b49c993b02bf0b8d5 Mon Sep 17 00:00:00 2001 +From: Stefan Behnel +Date: Sat, 17 Jan 2026 07:21:23 +0100 +Subject: [PATCH 2/2] Add missing "noexcept" to fix a memory leak. + +Fixes https://bugs.launchpad.net/lxml/+bug/2138421 +--- + src/lxml/etree.pyx | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/lxml/etree.pyx b/src/lxml/etree.pyx +index 562d95e..50cb71f 100644 +--- a/src/lxml/etree.pyx ++++ b/src/lxml/etree.pyx +@@ -657,7 +657,7 @@ cdef class DocInfo: + return root_name + + @cython.final +- cdef tree.xmlDtd* _get_c_dtd(self): ++ cdef tree.xmlDtd* _get_c_dtd(self) noexcept: + """"Return the DTD. Create it if it does not yet exist.""" + cdef xmlDoc* c_doc = self._doc._c_doc + cdef xmlNode* c_root_node +-- +2.53.0 + diff --git a/python3.14-lxml.spec b/python3.14-lxml.spec index dd4ab1f..9db61f4 100644 --- a/python3.14-lxml.spec +++ b/python3.14-lxml.spec @@ -18,9 +18,11 @@ URL: https://github.com/lxml/lxml Source0: lxml-%{version}-no-isoschematron-rng.tar.gz Source1: get-lxml-source.sh -# Fix a memory leak -# Resolved upstream: https://github.com/lxml/lxml/commit/459d51e316c319c8f49b3b7d08fb80cbc8585f49 -Patch0: fix-memory-leak.patch +# Fix two memory leaks +# Resolved upstream: +# https://github.com/lxml/lxml/commit/459d51e316c319c8f49b3b7d08fb80cbc8585f49 +# https://github.com/lxml/lxml/commit/39cdf11f5d2cf6e4f810202b6e415afd350d3df2 +Patch: fix-memory-leaks.patch BuildRequires: gcc BuildRequires: libxml2-devel