Fix session-config: mem leak and uninitialized ret value
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Thu, 9 Jun 2016 15:10:50 +0000 (11:10 -0400)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Mon, 4 Jul 2016 19:42:28 +0000 (15:42 -0400)
src/common/config/session-config.c

index 750eb948b96bfa6f9f8d69a9793c66bf0f21520c..3a1ff795c6e5e9ae66e7cbdb51782a34a2e583de 100644 (file)
@@ -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);
This page took 0.028882 seconds and 5 git commands to generate.