Fix session-config: mem leak and uninitialized ret value
[lttng-tools.git] / src / common / config / session-config.c
index 616434ecf572955d7c1952b9ba88b3fa9c17d0e3..3a1ff795c6e5e9ae66e7cbdb51782a34a2e583de 100644 (file)
@@ -1218,7 +1218,7 @@ int create_snapshot_session(const char *session_name, xmlNodePtr output_node)
                        snapshot_output_node; snapshot_output_node =
                        xmlNextElementSibling(snapshot_output_node)) {
                char *name = NULL;
-               uint64_t max_size = UINT64_MAX;
+               uint64_t max_size = DEFAULT_SNAPSHOT_MAX_SIZE;
                struct consumer_output output = { 0 };
                struct lttng_snapshot_output *snapshot_output = NULL;
 
@@ -1262,6 +1262,18 @@ int create_snapshot_session(const char *session_name, xmlNodePtr output_node)
                        goto error_snapshot_output;
                }
 
+               if (!name) {
+                       /* Generate a default name */
+                       int pret;
+                       pret = asprintf(&name, DEFAULT_SNAPSHOT_NAME "-%" PRIu32,
+                                       lttng_snapshot_output_get_id(snapshot_output));
+                       if (pret < 0) {
+                               name = NULL;
+                               PERROR("snprintf output name");
+                               goto error_snapshot_output;
+                       }
+               }
+
                ret = lttng_snapshot_output_set_name(name, snapshot_output);
                if (ret) {
                        goto error_snapshot_output;
@@ -3123,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);
@@ -3137,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;
@@ -3235,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;
 }
 
@@ -3307,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);
@@ -3495,6 +3513,7 @@ struct config_element *config_element_create(const char *name,
        if (!element->element) {
                free(element);
                element = NULL;
+               goto end;
        }
 
        if (internal_value) {
@@ -3617,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.029487 seconds and 5 git commands to generate.