summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2019-03-26 14:02:57 +0100
committerStefan Behnel <stefan_ml@behnel.de>2019-03-26 14:02:57 +0100
commit4baad26fd9931b3a7da9fb23cfe2c47d513c7940 (patch)
treef7082fc9bbcdcf223765b6fd1300e5df15404558
parentf2981e643b5b5a56089146bd5a093ecf7526dc12 (diff)
downloadpython-lxml-4baad26fd9931b3a7da9fb23cfe2c47d513c7940.tar.gz
Fix leak of output buffer in _XSLTResultTree.write_output().
-rw-r--r--CHANGES.txt9
-rw-r--r--src/lxml/xslt.pxi23
2 files changed, 18 insertions, 14 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 0b1aa718..a3fe72c2 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,15 @@
lxml changelog
==============
+4.3.3 (2019-03-26)
+==================
+
+Bugs fixed
+----------
+
+* Fix leak of output buffer and unclosed files in ``_XSLTResultTree.write_output()``.
+
+
4.3.2 (2019-02-29)
==================
diff --git a/src/lxml/xslt.pxi b/src/lxml/xslt.pxi
index d63a65ea..ee7b0719 100644
--- a/src/lxml/xslt.pxi
+++ b/src/lxml/xslt.pxi
@@ -720,7 +720,7 @@ cdef class _XSLTResultTree(_ElementTree):
"""
cdef _FilelikeWriter writer = None
cdef _Document doc
- cdef int r, c_compression
+ cdef int r, rclose, c_compression
cdef const_xmlChar* c_encoding = NULL
cdef tree.xmlOutputBuffer* c_buffer
@@ -733,23 +733,18 @@ cdef class _XSLTResultTree(_ElementTree):
if doc is None:
raise XSLTSaveError("No document to serialise")
c_compression = compression or 0
- if _isString(file):
- file_path = _encodeFilename(file)
- c_filename = _cstr(file_path)
+ xslt.LXML_GET_XSLT_ENCODING(c_encoding, self._xslt._c_style)
+ writer = _create_output_buffer(file, <const_char*>c_encoding, compression, &c_buffer, close=False)
+ if writer is None:
with nogil:
- r = xslt.xsltSaveResultToFilename(
- c_filename, doc._c_doc, self._xslt._c_style, c_compression)
- else:
- xslt.LXML_GET_XSLT_ENCODING(c_encoding, self._xslt._c_style)
- writer = _create_output_buffer(file, <const_char*>c_encoding, compression, &c_buffer, close=False)
- if writer is None:
- with nogil:
- r = xslt.xsltSaveResultTo(c_buffer, doc._c_doc, self._xslt._c_style)
- else:
r = xslt.xsltSaveResultTo(c_buffer, doc._c_doc, self._xslt._c_style)
+ rclose = tree.xmlOutputBufferClose(c_buffer)
+ else:
+ r = xslt.xsltSaveResultTo(c_buffer, doc._c_doc, self._xslt._c_style)
+ rclose = tree.xmlOutputBufferClose(c_buffer)
if writer is not None:
writer._exc_context._raise_if_stored()
- if r == -1:
+ if r < 0 or rclose < 0:
python.PyErr_SetFromErrno(XSLTSaveError) # raises
cdef _saveToStringAndSize(self, xmlChar** s, int* l):