Fix another memory leak

Related: RHEL-120801
This commit is contained in:
Charalampos Stratakis 2026-02-16 18:58:48 +01:00
parent 73c93fbe3f
commit c4a2a434f9
3 changed files with 57 additions and 26 deletions

View File

@ -1,23 +0,0 @@
From b9de95a1caf39c5eee35c984fd0b51ddd1b0d40e Mon Sep 17 00:00:00 2001
From: Stefan Behnel <stefan_ml@behnel.de>
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

52
fix-memory-leaks.patch Normal file
View File

@ -0,0 +1,52 @@
From 9abf22ef29816787256605a281e1413bd6063590 Mon Sep 17 00:00:00 2001
From: Stefan Behnel <stefan_ml@behnel.de>
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 <stefan_ml@behnel.de>
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

View File

@ -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