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
26
parser.c
26
parser.c
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user