mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-24 13:33:01 +03:00
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.
This commit is contained in:
committed by
Daniel Veillard
parent
868d92da89
commit
24464be639
10
HTMLparser.c
10
HTMLparser.c
@@ -6780,8 +6780,11 @@ htmlReadIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose,
|
|||||||
|
|
||||||
input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
|
input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
|
||||||
XML_CHAR_ENCODING_NONE);
|
XML_CHAR_ENCODING_NONE);
|
||||||
if (input == NULL)
|
if (input == NULL) {
|
||||||
|
if (ioclose != NULL)
|
||||||
|
ioclose(ioctx);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
}
|
||||||
ctxt = htmlNewParserCtxt();
|
ctxt = htmlNewParserCtxt();
|
||||||
if (ctxt == NULL) {
|
if (ctxt == NULL) {
|
||||||
xmlFreeParserInputBuffer(input);
|
xmlFreeParserInputBuffer(input);
|
||||||
@@ -6980,8 +6983,11 @@ htmlCtxtReadIO(htmlParserCtxtPtr ctxt, xmlInputReadCallback ioread,
|
|||||||
|
|
||||||
input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
|
input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
|
||||||
XML_CHAR_ENCODING_NONE);
|
XML_CHAR_ENCODING_NONE);
|
||||||
if (input == NULL)
|
if (input == NULL) {
|
||||||
|
if (ioclose != NULL)
|
||||||
|
ioclose(ioctx);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
}
|
||||||
stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);
|
stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);
|
||||||
if (stream == NULL) {
|
if (stream == NULL) {
|
||||||
xmlFreeParserInputBuffer(input);
|
xmlFreeParserInputBuffer(input);
|
||||||
|
|||||||
26
parser.c
26
parser.c
@@ -11984,11 +11984,15 @@ xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
|
|||||||
xmlParserCtxtPtr ctxt;
|
xmlParserCtxtPtr ctxt;
|
||||||
xmlParserInputPtr inputStream;
|
xmlParserInputPtr inputStream;
|
||||||
xmlParserInputBufferPtr buf;
|
xmlParserInputBufferPtr buf;
|
||||||
|
|
||||||
if (ioread == NULL) return(NULL);
|
if (ioread == NULL) return(NULL);
|
||||||
|
|
||||||
buf = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, enc);
|
buf = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, enc);
|
||||||
if (buf == NULL) return(NULL);
|
if (buf == NULL) {
|
||||||
|
if (ioclose != NULL)
|
||||||
|
ioclose(ioctx);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
ctxt = xmlNewParserCtxt();
|
ctxt = xmlNewParserCtxt();
|
||||||
if (ctxt == NULL) {
|
if (ctxt == NULL) {
|
||||||
@@ -12013,7 +12017,7 @@ xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
|
|||||||
memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1));
|
memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1));
|
||||||
if (user_data != NULL)
|
if (user_data != NULL)
|
||||||
ctxt->userData = user_data;
|
ctxt->userData = user_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
inputStream = xmlNewIOInputStream(ctxt, buf, enc);
|
inputStream = xmlNewIOInputStream(ctxt, buf, enc);
|
||||||
if (inputStream == NULL) {
|
if (inputStream == NULL) {
|
||||||
@@ -14787,7 +14791,7 @@ xmlReadFd(int fd, const char *URL, const char *encoding, int options)
|
|||||||
* @options: a combination of xmlParserOption
|
* @options: a combination of xmlParserOption
|
||||||
*
|
*
|
||||||
* parse an XML document from I/O functions and source and build a tree.
|
* parse an XML document from I/O functions and source and build a tree.
|
||||||
*
|
*
|
||||||
* Returns the resulting document tree
|
* Returns the resulting document tree
|
||||||
*/
|
*/
|
||||||
xmlDocPtr
|
xmlDocPtr
|
||||||
@@ -14803,8 +14807,11 @@ xmlReadIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose,
|
|||||||
|
|
||||||
input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
|
input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
|
||||||
XML_CHAR_ENCODING_NONE);
|
XML_CHAR_ENCODING_NONE);
|
||||||
if (input == NULL)
|
if (input == NULL) {
|
||||||
|
if (ioclose != NULL)
|
||||||
|
ioclose(ioctx);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
}
|
||||||
ctxt = xmlNewParserCtxt();
|
ctxt = xmlNewParserCtxt();
|
||||||
if (ctxt == NULL) {
|
if (ctxt == NULL) {
|
||||||
xmlFreeParserInputBuffer(input);
|
xmlFreeParserInputBuffer(input);
|
||||||
@@ -14830,7 +14837,7 @@ xmlReadIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose,
|
|||||||
*
|
*
|
||||||
* parse an XML in-memory document and build a tree.
|
* parse an XML in-memory document and build a tree.
|
||||||
* This reuses the existing @ctxt parser context
|
* This reuses the existing @ctxt parser context
|
||||||
*
|
*
|
||||||
* Returns the resulting document tree
|
* Returns the resulting document tree
|
||||||
*/
|
*/
|
||||||
xmlDocPtr
|
xmlDocPtr
|
||||||
@@ -14985,7 +14992,7 @@ xmlCtxtReadFd(xmlParserCtxtPtr ctxt, int fd,
|
|||||||
*
|
*
|
||||||
* parse an XML document from I/O functions and source and build a tree.
|
* parse an XML document from I/O functions and source and build a tree.
|
||||||
* This reuses the existing @ctxt parser context
|
* This reuses the existing @ctxt parser context
|
||||||
*
|
*
|
||||||
* Returns the resulting document tree
|
* Returns the resulting document tree
|
||||||
*/
|
*/
|
||||||
xmlDocPtr
|
xmlDocPtr
|
||||||
@@ -15006,8 +15013,11 @@ xmlCtxtReadIO(xmlParserCtxtPtr ctxt, xmlInputReadCallback ioread,
|
|||||||
|
|
||||||
input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
|
input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
|
||||||
XML_CHAR_ENCODING_NONE);
|
XML_CHAR_ENCODING_NONE);
|
||||||
if (input == NULL)
|
if (input == NULL) {
|
||||||
|
if (ioclose != NULL)
|
||||||
|
ioclose(ioctx);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
}
|
||||||
stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);
|
stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);
|
||||||
if (stream == NULL) {
|
if (stream == NULL) {
|
||||||
xmlFreeParserInputBuffer(input);
|
xmlFreeParserInputBuffer(input);
|
||||||
|
|||||||
13
xmlreader.c
13
xmlreader.c
@@ -5401,8 +5401,11 @@ xmlReaderForIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose,
|
|||||||
|
|
||||||
input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
|
input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
|
||||||
XML_CHAR_ENCODING_NONE);
|
XML_CHAR_ENCODING_NONE);
|
||||||
if (input == NULL)
|
if (input == NULL) {
|
||||||
|
if (ioclose != NULL)
|
||||||
|
ioclose(ioctx);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
}
|
||||||
reader = xmlNewTextReader(input, URL);
|
reader = xmlNewTextReader(input, URL);
|
||||||
if (reader == NULL) {
|
if (reader == NULL) {
|
||||||
xmlFreeParserInputBuffer(input);
|
xmlFreeParserInputBuffer(input);
|
||||||
@@ -5619,10 +5622,14 @@ xmlReaderNewIO(xmlTextReaderPtr reader, xmlInputReadCallback ioread,
|
|||||||
|
|
||||||
input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
|
input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
|
||||||
XML_CHAR_ENCODING_NONE);
|
XML_CHAR_ENCODING_NONE);
|
||||||
if (input == NULL)
|
if (input == NULL) {
|
||||||
return (-1);
|
if (ioclose != NULL)
|
||||||
|
ioclose(ioctx);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
return (xmlTextReaderSetup(reader, input, URL, encoding, options));
|
return (xmlTextReaderSetup(reader, input, URL, encoding, options));
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* *
|
* *
|
||||||
* Utilities *
|
* Utilities *
|
||||||
|
|||||||
Reference in New Issue
Block a user