1
0
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:
Lin Yi-Li
2012-05-10 16:14:55 +08:00
committed by Daniel Veillard
parent 868d92da89
commit 24464be639
3 changed files with 36 additions and 13 deletions

View File

@@ -6780,8 +6780,11 @@ htmlReadIO(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);
}
ctxt = htmlNewParserCtxt();
if (ctxt == NULL) {
xmlFreeParserInputBuffer(input);
@@ -6980,8 +6983,11 @@ htmlCtxtReadIO(htmlParserCtxtPtr ctxt, xmlInputReadCallback ioread,
input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
XML_CHAR_ENCODING_NONE);
if (input == NULL)
if (input == NULL) {
if (ioclose != NULL)
ioclose(ioctx);
return (NULL);
}
stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);
if (stream == NULL) {
xmlFreeParserInputBuffer(input);

View File

@@ -11984,11 +11984,15 @@ xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
xmlParserCtxtPtr ctxt;
xmlParserInputPtr inputStream;
xmlParserInputBufferPtr buf;
if (ioread == NULL) return(NULL);
buf = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, enc);
if (buf == NULL) return(NULL);
if (buf == NULL) {
if (ioclose != NULL)
ioclose(ioctx);
return (NULL);
}
ctxt = xmlNewParserCtxt();
if (ctxt == NULL) {
@@ -12013,7 +12017,7 @@ xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1));
if (user_data != NULL)
ctxt->userData = user_data;
}
}
inputStream = xmlNewIOInputStream(ctxt, buf, enc);
if (inputStream == NULL) {
@@ -14787,7 +14791,7 @@ xmlReadFd(int fd, const char *URL, const char *encoding, int options)
* @options: a combination of xmlParserOption
*
* parse an XML document from I/O functions and source and build a tree.
*
*
* Returns the resulting document tree
*/
xmlDocPtr
@@ -14803,8 +14807,11 @@ xmlReadIO(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);
}
ctxt = xmlNewParserCtxt();
if (ctxt == NULL) {
xmlFreeParserInputBuffer(input);
@@ -14830,7 +14837,7 @@ xmlReadIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose,
*
* parse an XML in-memory document and build a tree.
* This reuses the existing @ctxt parser context
*
*
* Returns the resulting document tree
*/
xmlDocPtr
@@ -14985,7 +14992,7 @@ xmlCtxtReadFd(xmlParserCtxtPtr ctxt, int fd,
*
* parse an XML document from I/O functions and source and build a tree.
* This reuses the existing @ctxt parser context
*
*
* Returns the resulting document tree
*/
xmlDocPtr
@@ -15006,8 +15013,11 @@ xmlCtxtReadIO(xmlParserCtxtPtr ctxt, xmlInputReadCallback ioread,
input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
XML_CHAR_ENCODING_NONE);
if (input == NULL)
if (input == NULL) {
if (ioclose != NULL)
ioclose(ioctx);
return (NULL);
}
stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);
if (stream == NULL) {
xmlFreeParserInputBuffer(input);

View File

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