summaryrefslogtreecommitdiff
path: root/encoding.c
diff options
context:
space:
mode:
authorXiaoming Ni <nixiaoming@huawei.com>2020-12-07 20:19:53 +0800
committerNick Wellnhofer <wellnhofer@aevum.de>2020-12-07 14:38:14 +0100
commit649d02eaa419fa72ae6b131718a4ac77063d7a5a (patch)
treef0e11dff0b5b1f6589a42c93fc8d9e56ae98b94d /encoding.c
parentcb7a572b3e7f568f1ebc8d91b1b8826a8ce3baa8 (diff)
downloadlibxml2-649d02eaa419fa72ae6b131718a4ac77063d7a5a.tar.gz
encoding: fix memleak in xmlRegisterCharEncodingHandler()
The return type of xmlRegisterCharEncodingHandler() is void. The invoker cannot determine whether xmlRegisterCharEncodingHandler() is executed successfully. when nbCharEncodingHandler >= MAX_ENCODING_HANDLERS, the "handler" is not added to the array "handlers". As a result, the memory of "handler" cannot be managed and released: memory leakage. so add "xmlfree(handler)" to fix memory leakage on the failure branch of xmlRegisterCharEncodingHandler(). Reported-by: wuqing <wuqing30@huawei.com> Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
Diffstat (limited to 'encoding.c')
-rw-r--r--encoding.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/encoding.c b/encoding.c
index 264f60bb..d67c16d9 100644
--- a/encoding.c
+++ b/encoding.c
@@ -1488,16 +1488,25 @@ xmlRegisterCharEncodingHandler(xmlCharEncodingHandlerPtr handler) {
if ((handler == NULL) || (handlers == NULL)) {
xmlEncodingErr(XML_I18N_NO_HANDLER,
"xmlRegisterCharEncodingHandler: NULL handler !\n", NULL);
- return;
+ goto free_handler;
}
if (nbCharEncodingHandler >= MAX_ENCODING_HANDLERS) {
xmlEncodingErr(XML_I18N_EXCESS_HANDLER,
"xmlRegisterCharEncodingHandler: Too many handler registered, see %s\n",
"MAX_ENCODING_HANDLERS");
- return;
+ goto free_handler;
}
handlers[nbCharEncodingHandler++] = handler;
+ return;
+
+free_handler:
+ if (handler != NULL) {
+ if (handler->name != NULL) {
+ xmlFree(handler->name);
+ }
+ xmlFree(handler);
+ }
}
/**