diff options
author | Lin Yi-Li <record.nctu.cis91@gmail.com> | 2012-05-10 16:14:55 +0800 |
---|---|---|
committer | Daniel Veillard <veillard@redhat.com> | 2012-05-10 16:14:55 +0800 |
commit | 24464be6390bc61a0f0e17890fbfc9c581434e29 (patch) | |
tree | 2ccda2d899709a84de59a2649770b902061c115a /xmlreader.c | |
parent | 868d92da8915fc5dc5e329d93cc7882370a28475 (diff) | |
download | libxml2-24464be6390bc61a0f0e17890fbfc9c581434e29.tar.gz |
Avoid memory leak if xmlParserInputBufferCreateIO fails
For https://bugzilla.gnome.org/show_bug.cgi?id=643949
In case of error on an IO creation input the given context
is terminated with the given close function, except if the
error happened in xmlParserInputBufferCreateIO. This can
lead to a resource leak which is fixed by this patch.
Diffstat (limited to 'xmlreader.c')
-rw-r--r-- | xmlreader.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/xmlreader.c b/xmlreader.c index 864abf0a..ef41927e 100644 --- a/xmlreader.c +++ b/xmlreader.c @@ -5401,8 +5401,11 @@ xmlReaderForIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose, input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, XML_CHAR_ENCODING_NONE); - if (input == NULL) + if (input == NULL) { + if (ioclose != NULL) + ioclose(ioctx); return (NULL); + } reader = xmlNewTextReader(input, URL); if (reader == NULL) { xmlFreeParserInputBuffer(input); @@ -5619,10 +5622,14 @@ xmlReaderNewIO(xmlTextReaderPtr reader, xmlInputReadCallback ioread, input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, XML_CHAR_ENCODING_NONE); - if (input == NULL) - return (-1); + if (input == NULL) { + if (ioclose != NULL) + ioclose(ioctx); + return (NULL); + } return (xmlTextReaderSetup(reader, input, URL, encoding, options)); } + /************************************************************************ * * * Utilities * |