Fix: lttng-add-context: leak of application context parameters
[lttng-tools.git] / src / bin / lttng / commands / add_context.c
index 994cd49eb32037b898dc3fcac9853c3681ebd9a9..16389e11398573d71f7c4e81eb61dde06688d4d9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 EfficiOS Inc.
  * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * SPDX-License-Identifier: GPL-2.0-only
@@ -19,6 +19,7 @@
 
 #include <urcu/list.h>
 
+#include <lttng/domain-internal.h>
 #include <common/mi-lttng.h>
 
 #include "../command.h"
@@ -95,6 +96,7 @@ enum context_type {
        CONTEXT_VGID         = 38,
        CONTEXT_VEGID        = 39,
        CONTEXT_VSGID        = 40,
+       CONTEXT_TIME_NS      = 41,
 };
 
 /*
@@ -264,6 +266,7 @@ const struct ctx_opts {
        { (char *) "mnt_ns", CONTEXT_MNT_NS },
        { (char *) "net_ns", CONTEXT_NET_NS },
        { (char *) "pid_ns", CONTEXT_PID_NS },
+       { (char *) "time_ns", CONTEXT_TIME_NS },
        { (char *) "user_ns", CONTEXT_USER_NS },
        { (char *) "uts_ns", CONTEXT_UTS_NS },
        { (char *) "uid", CONTEXT_UID },
@@ -808,11 +811,13 @@ static int add_context(char *session_name)
                } else {
                        if (opt_channel_name) {
                                MSG("%s context %s added to channel %s",
-                                               get_domain_str(dom.type), type->opt->symbol,
+                                               lttng_domain_type_str(dom.type),
+                                               type->opt->symbol,
                                                opt_channel_name);
                        } else {
                                MSG("%s context %s added to all channels",
-                                               get_domain_str(dom.type), type->opt->symbol);
+                                               lttng_domain_type_str(dom.type),
+                                               type->opt->symbol);
                        }
                        success = 1;
                }
@@ -866,6 +871,10 @@ void destroy_ctx_type(struct ctx_type *type)
        }
        if (type->opt) {
                free(type->opt->symbol);
+               if (type->opt->ctx_type == CONTEXT_APP_CONTEXT) {
+                       free(type->opt->u.app_ctx.ctx_name);
+                       free(type->opt->u.app_ctx.provider_name);
+               }
        }
        free(type->opt);
        free(type);
@@ -1147,8 +1156,8 @@ int cmd_add_context(int argc, const char **argv)
                goto end;
        }
 
-       ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace +
-                       opt_jul + opt_log4j);
+       ret = print_missing_or_multiple_domains(
+                       opt_kernel + opt_userspace + opt_jul + opt_log4j, true);
        if (ret) {
                ret = CMD_ERROR;
                goto end;
This page took 0.024739 seconds and 4 git commands to generate.