aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2024-05-06 11:36:25 +0200
committerNick Wellnhofer <wellnhofer@aevum.de>2024-05-06 17:40:15 +0200
commit72e9267c32bd093b2c925eaebefc951c0cfde977 (patch)
treec8d79d14bcab01287acaeaaa1b20141d8d17f7a3
parent3afaff7e8e75bbfe74187e5c8577865ff64ba3a3 (diff)
downloadlibxml2-upstream-master.tar.gz
html: Fix memory leak after malloc failureupstream-master
-rw-r--r--HTMLtree.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/HTMLtree.c b/HTMLtree.c
index acdde75d..6e8baf48 100644
--- a/HTMLtree.c
+++ b/HTMLtree.c
@@ -513,7 +513,10 @@ htmlNodeDumpFileFormat(FILE *out, xmlDocPtr doc,
*/
handler = htmlFindOutputEncoder(encoding);
buf = xmlOutputBufferCreateFile(out, handler);
- if (buf == NULL) return(0);
+ if (buf == NULL) {
+ xmlCharEncCloseFunc(handler);
+ return(0);
+ }
htmlNodeDumpFormatOutput(buf, doc, cur, NULL, format);
@@ -563,8 +566,10 @@ htmlDocDumpMemoryFormat(xmlDocPtr cur, xmlChar**mem, int *size, int format) {
encoding = (const char *) htmlGetMetaEncoding(cur);
handler = htmlFindOutputEncoder(encoding);
buf = xmlAllocOutputBufferInternal(handler);
- if (buf == NULL)
+ if (buf == NULL) {
+ xmlCharEncCloseFunc(handler);
return;
+ }
htmlDocContentDumpFormatOutput(buf, cur, NULL, format);
@@ -1029,7 +1034,10 @@ htmlDocDump(FILE *f, xmlDocPtr cur) {
encoding = (const char *) htmlGetMetaEncoding(cur);
handler = htmlFindOutputEncoder(encoding);
buf = xmlOutputBufferCreateFile(f, handler);
- if (buf == NULL) return(-1);
+ if (buf == NULL) {
+ xmlCharEncCloseFunc(handler);
+ return(-1);
+ }
htmlDocContentDumpOutput(buf, cur, NULL);
ret = xmlOutputBufferClose(buf);
@@ -1060,7 +1068,10 @@ htmlSaveFile(const char *filename, xmlDocPtr cur) {
encoding = (const char *) htmlGetMetaEncoding(cur);
handler = htmlFindOutputEncoder(encoding);
buf = xmlOutputBufferCreateFilename(filename, handler, cur->compression);
- if (buf == NULL) return(0);
+ if (buf == NULL) {
+ xmlCharEncCloseFunc(handler);
+ return(0);
+ }
htmlDocContentDumpOutput(buf, cur, NULL);
@@ -1101,7 +1112,10 @@ htmlSaveFileFormat(const char *filename, xmlDocPtr cur,
* save the content to a temp buffer.
*/
buf = xmlOutputBufferCreateFilename(filename, handler, 0);
- if (buf == NULL) return(0);
+ if (buf == NULL) {
+ xmlCharEncCloseFunc(handler);
+ return(0);
+ }
htmlDocContentDumpFormatOutput(buf, cur, encoding, format);