mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-23 01:52:48 +03:00
io: Always consume encoding handler when creating output buffers
Also free encoding handler in error case. Remove xmlAllocOutputBufferInternal which was identical to xmlAllocOutputBuffer.
This commit is contained in:
22
HTMLtree.c
22
HTMLtree.c
@@ -508,10 +508,8 @@ htmlNodeDumpFileFormat(FILE *out, xmlDocPtr doc,
|
|||||||
*/
|
*/
|
||||||
handler = htmlFindOutputEncoder(encoding);
|
handler = htmlFindOutputEncoder(encoding);
|
||||||
buf = xmlOutputBufferCreateFile(out, handler);
|
buf = xmlOutputBufferCreateFile(out, handler);
|
||||||
if (buf == NULL) {
|
if (buf == NULL)
|
||||||
xmlCharEncCloseFunc(handler);
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
|
||||||
|
|
||||||
htmlNodeDumpFormatOutput(buf, doc, cur, NULL, format);
|
htmlNodeDumpFormatOutput(buf, doc, cur, NULL, format);
|
||||||
|
|
||||||
@@ -560,11 +558,9 @@ htmlDocDumpMemoryFormat(xmlDocPtr cur, xmlChar**mem, int *size, int format) {
|
|||||||
|
|
||||||
encoding = (const char *) htmlGetMetaEncoding(cur);
|
encoding = (const char *) htmlGetMetaEncoding(cur);
|
||||||
handler = htmlFindOutputEncoder(encoding);
|
handler = htmlFindOutputEncoder(encoding);
|
||||||
buf = xmlAllocOutputBufferInternal(handler);
|
buf = xmlAllocOutputBuffer(handler);
|
||||||
if (buf == NULL) {
|
if (buf == NULL)
|
||||||
xmlCharEncCloseFunc(handler);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
htmlDocContentDumpFormatOutput(buf, cur, NULL, format);
|
htmlDocContentDumpFormatOutput(buf, cur, NULL, format);
|
||||||
|
|
||||||
@@ -1029,10 +1025,8 @@ htmlDocDump(FILE *f, xmlDocPtr cur) {
|
|||||||
encoding = (const char *) htmlGetMetaEncoding(cur);
|
encoding = (const char *) htmlGetMetaEncoding(cur);
|
||||||
handler = htmlFindOutputEncoder(encoding);
|
handler = htmlFindOutputEncoder(encoding);
|
||||||
buf = xmlOutputBufferCreateFile(f, handler);
|
buf = xmlOutputBufferCreateFile(f, handler);
|
||||||
if (buf == NULL) {
|
if (buf == NULL)
|
||||||
xmlCharEncCloseFunc(handler);
|
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
|
||||||
htmlDocContentDumpOutput(buf, cur, NULL);
|
htmlDocContentDumpOutput(buf, cur, NULL);
|
||||||
|
|
||||||
ret = xmlOutputBufferClose(buf);
|
ret = xmlOutputBufferClose(buf);
|
||||||
@@ -1063,10 +1057,8 @@ htmlSaveFile(const char *filename, xmlDocPtr cur) {
|
|||||||
encoding = (const char *) htmlGetMetaEncoding(cur);
|
encoding = (const char *) htmlGetMetaEncoding(cur);
|
||||||
handler = htmlFindOutputEncoder(encoding);
|
handler = htmlFindOutputEncoder(encoding);
|
||||||
buf = xmlOutputBufferCreateFilename(filename, handler, cur->compression);
|
buf = xmlOutputBufferCreateFilename(filename, handler, cur->compression);
|
||||||
if (buf == NULL) {
|
if (buf == NULL)
|
||||||
xmlCharEncCloseFunc(handler);
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
|
||||||
|
|
||||||
htmlDocContentDumpOutput(buf, cur, NULL);
|
htmlDocContentDumpOutput(buf, cur, NULL);
|
||||||
|
|
||||||
@@ -1107,10 +1099,8 @@ htmlSaveFileFormat(const char *filename, xmlDocPtr cur,
|
|||||||
* save the content to a temp buffer.
|
* save the content to a temp buffer.
|
||||||
*/
|
*/
|
||||||
buf = xmlOutputBufferCreateFilename(filename, handler, 0);
|
buf = xmlOutputBufferCreateFilename(filename, handler, 0);
|
||||||
if (buf == NULL) {
|
if (buf == NULL)
|
||||||
xmlCharEncCloseFunc(handler);
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
|
||||||
|
|
||||||
htmlDocContentDumpFormatOutput(buf, cur, encoding, format);
|
htmlDocContentDumpFormatOutput(buf, cur, encoding, format);
|
||||||
|
|
||||||
|
@@ -32,8 +32,6 @@ xmlNewInputBufferMemory(const void *mem, size_t size, int flags,
|
|||||||
xmlCharEncoding enc);
|
xmlCharEncoding enc);
|
||||||
|
|
||||||
#ifdef LIBXML_OUTPUT_ENABLED
|
#ifdef LIBXML_OUTPUT_ENABLED
|
||||||
XML_HIDDEN xmlOutputBufferPtr
|
|
||||||
xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr encoder);
|
|
||||||
XML_HIDDEN void
|
XML_HIDDEN void
|
||||||
xmlOutputBufferWriteQuotedString(xmlOutputBufferPtr buf,
|
xmlOutputBufferWriteQuotedString(xmlOutputBufferPtr buf,
|
||||||
const xmlChar *string);
|
const xmlChar *string);
|
||||||
|
78
xmlIO.c
78
xmlIO.c
@@ -1237,6 +1237,8 @@ xmlAllocParserInputBuffer(xmlCharEncoding enc) {
|
|||||||
*
|
*
|
||||||
* Create a buffered parser output
|
* Create a buffered parser output
|
||||||
*
|
*
|
||||||
|
* Consumes @encoder even in error case.
|
||||||
|
*
|
||||||
* Returns the new parser output or NULL
|
* Returns the new parser output or NULL
|
||||||
*/
|
*/
|
||||||
xmlOutputBufferPtr
|
xmlOutputBufferPtr
|
||||||
@@ -1245,11 +1247,13 @@ xmlAllocOutputBuffer(xmlCharEncodingHandlerPtr encoder) {
|
|||||||
|
|
||||||
ret = (xmlOutputBufferPtr) xmlMalloc(sizeof(xmlOutputBuffer));
|
ret = (xmlOutputBufferPtr) xmlMalloc(sizeof(xmlOutputBuffer));
|
||||||
if (ret == NULL) {
|
if (ret == NULL) {
|
||||||
|
xmlCharEncCloseFunc(encoder);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
memset(ret, 0, sizeof(xmlOutputBuffer));
|
memset(ret, 0, sizeof(xmlOutputBuffer));
|
||||||
ret->buffer = xmlBufCreate(MINLEN);
|
ret->buffer = xmlBufCreate(MINLEN);
|
||||||
if (ret->buffer == NULL) {
|
if (ret->buffer == NULL) {
|
||||||
|
xmlCharEncCloseFunc(encoder);
|
||||||
xmlFree(ret);
|
xmlFree(ret);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
@@ -1258,8 +1262,7 @@ xmlAllocOutputBuffer(xmlCharEncodingHandlerPtr encoder) {
|
|||||||
if (encoder != NULL) {
|
if (encoder != NULL) {
|
||||||
ret->conv = xmlBufCreate(MINLEN);
|
ret->conv = xmlBufCreate(MINLEN);
|
||||||
if (ret->conv == NULL) {
|
if (ret->conv == NULL) {
|
||||||
xmlBufFree(ret->buffer);
|
xmlOutputBufferClose(ret);
|
||||||
xmlFree(ret);
|
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1276,53 +1279,6 @@ xmlAllocOutputBuffer(xmlCharEncodingHandlerPtr encoder) {
|
|||||||
|
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* xmlAllocOutputBufferInternal:
|
|
||||||
* @encoder: the encoding converter or NULL
|
|
||||||
*
|
|
||||||
* Create a buffered parser output
|
|
||||||
*
|
|
||||||
* Returns the new parser output or NULL
|
|
||||||
*/
|
|
||||||
xmlOutputBufferPtr
|
|
||||||
xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr encoder) {
|
|
||||||
xmlOutputBufferPtr ret;
|
|
||||||
|
|
||||||
ret = (xmlOutputBufferPtr) xmlMalloc(sizeof(xmlOutputBuffer));
|
|
||||||
if (ret == NULL) {
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
memset(ret, 0, sizeof(xmlOutputBuffer));
|
|
||||||
ret->buffer = xmlBufCreate(MINLEN);
|
|
||||||
if (ret->buffer == NULL) {
|
|
||||||
xmlFree(ret);
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret->encoder = encoder;
|
|
||||||
if (encoder != NULL) {
|
|
||||||
ret->conv = xmlBufCreate(MINLEN);
|
|
||||||
if (ret->conv == NULL) {
|
|
||||||
xmlBufFree(ret->buffer);
|
|
||||||
xmlFree(ret);
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This call is designed to initiate the encoder state
|
|
||||||
*/
|
|
||||||
xmlCharEncOutput(ret, 1);
|
|
||||||
} else
|
|
||||||
ret->conv = NULL;
|
|
||||||
ret->writecallback = NULL;
|
|
||||||
ret->closecallback = NULL;
|
|
||||||
ret->context = NULL;
|
|
||||||
ret->written = 0;
|
|
||||||
|
|
||||||
return(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* LIBXML_OUTPUT_ENABLED */
|
#endif /* LIBXML_OUTPUT_ENABLED */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1536,10 +1492,9 @@ __xmlOutputBufferCreateFilename(const char *URI,
|
|||||||
/*
|
/*
|
||||||
* Allocate the Output buffer front-end.
|
* Allocate the Output buffer front-end.
|
||||||
*/
|
*/
|
||||||
ret = xmlAllocOutputBufferInternal(encoder);
|
ret = xmlAllocOutputBuffer(encoder);
|
||||||
if (ret == NULL) {
|
if (ret == NULL) {
|
||||||
xmlFree(unescaped);
|
xmlFree(unescaped);
|
||||||
xmlCharEncCloseFunc(encoder);
|
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1589,6 +1544,8 @@ __xmlOutputBufferCreateFilename(const char *URI,
|
|||||||
* TODO: currently if compression is set, the library only support
|
* TODO: currently if compression is set, the library only support
|
||||||
* writing to a local file.
|
* writing to a local file.
|
||||||
*
|
*
|
||||||
|
* Consumes @encoder even in error case.
|
||||||
|
*
|
||||||
* Returns the new output or NULL
|
* Returns the new output or NULL
|
||||||
*/
|
*/
|
||||||
xmlOutputBufferPtr
|
xmlOutputBufferPtr
|
||||||
@@ -1643,6 +1600,8 @@ xmlParserInputBufferCreateFile(FILE *file, xmlCharEncoding enc) {
|
|||||||
* Create a buffered output for the progressive saving to a FILE *
|
* Create a buffered output for the progressive saving to a FILE *
|
||||||
* buffered C I/O
|
* buffered C I/O
|
||||||
*
|
*
|
||||||
|
* Consumes @encoder even in error case.
|
||||||
|
*
|
||||||
* Returns the new parser output or NULL
|
* Returns the new parser output or NULL
|
||||||
*/
|
*/
|
||||||
xmlOutputBufferPtr
|
xmlOutputBufferPtr
|
||||||
@@ -1651,7 +1610,7 @@ xmlOutputBufferCreateFile(FILE *file, xmlCharEncodingHandlerPtr encoder) {
|
|||||||
|
|
||||||
if (file == NULL) return(NULL);
|
if (file == NULL) return(NULL);
|
||||||
|
|
||||||
ret = xmlAllocOutputBufferInternal(encoder);
|
ret = xmlAllocOutputBuffer(encoder);
|
||||||
if (ret != NULL) {
|
if (ret != NULL) {
|
||||||
ret->context = file;
|
ret->context = file;
|
||||||
ret->writecallback = xmlFileWrite;
|
ret->writecallback = xmlFileWrite;
|
||||||
@@ -1668,6 +1627,8 @@ xmlOutputBufferCreateFile(FILE *file, xmlCharEncodingHandlerPtr encoder) {
|
|||||||
*
|
*
|
||||||
* Create a buffered output for the progressive saving to a xmlBuffer
|
* Create a buffered output for the progressive saving to a xmlBuffer
|
||||||
*
|
*
|
||||||
|
* Consumes @encoder even in error case.
|
||||||
|
*
|
||||||
* Returns the new parser output or NULL
|
* Returns the new parser output or NULL
|
||||||
*/
|
*/
|
||||||
xmlOutputBufferPtr
|
xmlOutputBufferPtr
|
||||||
@@ -1932,6 +1893,8 @@ xmlNewInputBufferString(const char *str, int flags) {
|
|||||||
* Create a buffered output for the progressive saving
|
* Create a buffered output for the progressive saving
|
||||||
* to a file descriptor
|
* to a file descriptor
|
||||||
*
|
*
|
||||||
|
* Consumes @encoder even in error case.
|
||||||
|
*
|
||||||
* Returns the new parser output or NULL
|
* Returns the new parser output or NULL
|
||||||
*/
|
*/
|
||||||
xmlOutputBufferPtr
|
xmlOutputBufferPtr
|
||||||
@@ -1940,7 +1903,7 @@ xmlOutputBufferCreateFd(int fd, xmlCharEncodingHandlerPtr encoder) {
|
|||||||
|
|
||||||
if (fd < 0) return(NULL);
|
if (fd < 0) return(NULL);
|
||||||
|
|
||||||
ret = xmlAllocOutputBufferInternal(encoder);
|
ret = xmlAllocOutputBuffer(encoder);
|
||||||
if (ret != NULL) {
|
if (ret != NULL) {
|
||||||
ret->context = (void *) (ptrdiff_t) fd;
|
ret->context = (void *) (ptrdiff_t) fd;
|
||||||
ret->writecallback = xmlFdWrite;
|
ret->writecallback = xmlFdWrite;
|
||||||
@@ -1997,6 +1960,8 @@ xmlParserInputBufferCreateIO(xmlInputReadCallback ioread,
|
|||||||
* Create a buffered output for the progressive saving
|
* Create a buffered output for the progressive saving
|
||||||
* to an I/O handler
|
* to an I/O handler
|
||||||
*
|
*
|
||||||
|
* Consumes @encoder even in error case.
|
||||||
|
*
|
||||||
* Returns the new parser output or NULL
|
* Returns the new parser output or NULL
|
||||||
*/
|
*/
|
||||||
xmlOutputBufferPtr
|
xmlOutputBufferPtr
|
||||||
@@ -2005,9 +1970,12 @@ xmlOutputBufferCreateIO(xmlOutputWriteCallback iowrite,
|
|||||||
xmlCharEncodingHandlerPtr encoder) {
|
xmlCharEncodingHandlerPtr encoder) {
|
||||||
xmlOutputBufferPtr ret;
|
xmlOutputBufferPtr ret;
|
||||||
|
|
||||||
if (iowrite == NULL) return(NULL);
|
if (iowrite == NULL) {
|
||||||
|
xmlCharEncCloseFunc(encoder);
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
ret = xmlAllocOutputBufferInternal(encoder);
|
ret = xmlAllocOutputBuffer(encoder);
|
||||||
if (ret != NULL) {
|
if (ret != NULL) {
|
||||||
ret->context = (void *) ioctx;
|
ret->context = (void *) ioctx;
|
||||||
ret->writecallback = iowrite;
|
ret->writecallback = iowrite;
|
||||||
|
@@ -1960,7 +1960,6 @@ xmlSaveToFd(int fd, const char *encoding, int options)
|
|||||||
if (ret == NULL) return(NULL);
|
if (ret == NULL) return(NULL);
|
||||||
ret->buf = xmlOutputBufferCreateFd(fd, ret->handler);
|
ret->buf = xmlOutputBufferCreateFd(fd, ret->handler);
|
||||||
if (ret->buf == NULL) {
|
if (ret->buf == NULL) {
|
||||||
xmlCharEncCloseFunc(ret->handler);
|
|
||||||
xmlFreeSaveCtxt(ret);
|
xmlFreeSaveCtxt(ret);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
@@ -1990,7 +1989,6 @@ xmlSaveToFilename(const char *filename, const char *encoding, int options)
|
|||||||
ret->buf = xmlOutputBufferCreateFilename(filename, ret->handler,
|
ret->buf = xmlOutputBufferCreateFilename(filename, ret->handler,
|
||||||
compression);
|
compression);
|
||||||
if (ret->buf == NULL) {
|
if (ret->buf == NULL) {
|
||||||
xmlCharEncCloseFunc(ret->handler);
|
|
||||||
xmlFreeSaveCtxt(ret);
|
xmlFreeSaveCtxt(ret);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
@@ -2018,7 +2016,6 @@ xmlSaveToBuffer(xmlBufferPtr buffer, const char *encoding, int options)
|
|||||||
if (ret == NULL) return(NULL);
|
if (ret == NULL) return(NULL);
|
||||||
ret->buf = xmlOutputBufferCreateBuffer(buffer, ret->handler);
|
ret->buf = xmlOutputBufferCreateBuffer(buffer, ret->handler);
|
||||||
if (ret->buf == NULL) {
|
if (ret->buf == NULL) {
|
||||||
xmlCharEncCloseFunc(ret->handler);
|
|
||||||
xmlFreeSaveCtxt(ret);
|
xmlFreeSaveCtxt(ret);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
@@ -2049,7 +2046,6 @@ xmlSaveToIO(xmlOutputWriteCallback iowrite,
|
|||||||
if (ret == NULL) return(NULL);
|
if (ret == NULL) return(NULL);
|
||||||
ret->buf = xmlOutputBufferCreateIO(iowrite, ioclose, ioctx, ret->handler);
|
ret->buf = xmlOutputBufferCreateIO(iowrite, ioclose, ioctx, ret->handler);
|
||||||
if (ret->buf == NULL) {
|
if (ret->buf == NULL) {
|
||||||
xmlCharEncCloseFunc(ret->handler);
|
|
||||||
xmlFreeSaveCtxt(ret);
|
xmlFreeSaveCtxt(ret);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
@@ -2554,7 +2550,6 @@ xmlDocDumpFormatMemoryEnc(xmlDocPtr out_doc, xmlChar **doc_txt_ptr,
|
|||||||
out_buff = xmlAllocOutputBuffer(conv_hdlr);
|
out_buff = xmlAllocOutputBuffer(conv_hdlr);
|
||||||
if (out_buff == NULL ) {
|
if (out_buff == NULL ) {
|
||||||
xmlSaveErrMemory(NULL);
|
xmlSaveErrMemory(NULL);
|
||||||
xmlCharEncCloseFunc(conv_hdlr);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user