From 4640a5266823159d965e0ade209186a9ccb0db99 Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Thu, 9 Jun 2016 11:10:50 -0400 Subject: [PATCH] Fix session-config: mem leak and uninitialized ret value --- src/common/config/session-config.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/common/config/session-config.c b/src/common/config/session-config.c index 750eb948b..3a1ff795c 100644 --- a/src/common/config/session-config.c +++ b/src/common/config/session-config.c @@ -3135,6 +3135,7 @@ struct config_document *config_document_get(const char *path) } end: + fini_session_config_validation_ctx(&validation_ctx); return document; error: xmlFreeDoc(document->document); @@ -3149,13 +3150,15 @@ void config_document_free(struct config_document *document) xmlFreeDoc(document->document); document->document = NULL; } + + free(document); } LTTNG_HIDDEN int config_document_replace_element_value(struct config_document *document, const char *xpath, const char *value) { - int ret; + int ret = 0; int xpath_result_size; xmlXPathContextPtr xpath_context = NULL; @@ -3247,6 +3250,7 @@ int config_load_configuration_sessions(struct config_document *document, ret = load_session_from_document(document, session_name, &validation_ctx, override); end: + fini_session_config_validation_ctx(&validation_ctx); return ret; } @@ -3319,14 +3323,16 @@ int config_document_replace_element(struct config_document *document, goto end; } - old_node = xmlReplaceNode(xpath_result_set->nodeTab[0], copy); + if (xpath_result_set->nodeTab[0]->type != XML_NAMESPACE_DECL) + xpath_result_set->nodeTab[0] = NULL; if (!old_node) { ret = -LTTNG_ERR_CONFIG_REPLACEMENT; xmlFreeNode(copy); goto end; } - xmlFree(old_node); + xmlUnlinkNode(old_node); + xmlFreeNode(old_node); end: xmlXPathFreeContext(xpath_context); xmlXPathFreeObject(xpath_object); @@ -3630,8 +3636,8 @@ end: LTTNG_HIDDEN void config_element_free(struct config_element *element) { - if (element->element) { - xmlFree(element->element); + if (element && element->element) { + xmlFreeNode(element->element); } free(element); -- 2.34.1