mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-01-12 09:17:37 +03:00
Fix memory leaks of encoding handlers in xmlsave.c
Fix leak of iconv/ICU encoding handler in xmlSaveToBuffer. Fix leaks of iconv/ICU encoding handlers in xmlSaveTo* error paths. Closes #127.
This commit is contained in:
parent
2a357ab99e
commit
42942066e1
26
xmlsave.c
26
xmlsave.c
@ -1802,6 +1802,7 @@ xmlSaveToFd(int fd, const char *encoding, int options)
|
||||
if (ret == NULL) return(NULL);
|
||||
ret->buf = xmlOutputBufferCreateFd(fd, ret->handler);
|
||||
if (ret->buf == NULL) {
|
||||
xmlCharEncCloseFunc(ret->handler);
|
||||
xmlFreeSaveCtxt(ret);
|
||||
return(NULL);
|
||||
}
|
||||
@ -1831,6 +1832,7 @@ xmlSaveToFilename(const char *filename, const char *encoding, int options)
|
||||
ret->buf = xmlOutputBufferCreateFilename(filename, ret->handler,
|
||||
compression);
|
||||
if (ret->buf == NULL) {
|
||||
xmlCharEncCloseFunc(ret->handler);
|
||||
xmlFreeSaveCtxt(ret);
|
||||
return(NULL);
|
||||
}
|
||||
@ -1853,28 +1855,15 @@ xmlSaveCtxtPtr
|
||||
xmlSaveToBuffer(xmlBufferPtr buffer, const char *encoding, int options)
|
||||
{
|
||||
xmlSaveCtxtPtr ret;
|
||||
xmlOutputBufferPtr out_buff;
|
||||
xmlCharEncodingHandlerPtr handler;
|
||||
|
||||
ret = xmlNewSaveCtxt(encoding, options);
|
||||
if (ret == NULL) return(NULL);
|
||||
|
||||
if (encoding != NULL) {
|
||||
handler = xmlFindCharEncodingHandler(encoding);
|
||||
if (handler == NULL) {
|
||||
xmlFree(ret);
|
||||
return(NULL);
|
||||
}
|
||||
} else
|
||||
handler = NULL;
|
||||
out_buff = xmlOutputBufferCreateBuffer(buffer, handler);
|
||||
if (out_buff == NULL) {
|
||||
xmlFree(ret);
|
||||
if (handler) xmlCharEncCloseFunc(handler);
|
||||
return(NULL);
|
||||
ret->buf = xmlOutputBufferCreateBuffer(buffer, ret->handler);
|
||||
if (ret->buf == NULL) {
|
||||
xmlCharEncCloseFunc(ret->handler);
|
||||
xmlFreeSaveCtxt(ret);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
ret->buf = out_buff;
|
||||
return(ret);
|
||||
}
|
||||
|
||||
@ -1902,6 +1891,7 @@ xmlSaveToIO(xmlOutputWriteCallback iowrite,
|
||||
if (ret == NULL) return(NULL);
|
||||
ret->buf = xmlOutputBufferCreateIO(iowrite, ioclose, ioctx, ret->handler);
|
||||
if (ret->buf == NULL) {
|
||||
xmlCharEncCloseFunc(ret->handler);
|
||||
xmlFreeSaveCtxt(ret);
|
||||
return(NULL);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user