Fix: lttng: poptGetArg doesn't provide string ownership
[lttng-tools.git] / src / bin / lttng / commands / disable_events.cpp
index d2948ac041928814f51a7ebd0610b5811fcecfee..bf8ed6e3005004c679381e3929b1f27101ddc6dd 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "../command.hpp"
 
-static char *opt_event_list;
 static int opt_kernel;
 static char *opt_channel_name;
 static char *opt_session_name;
@@ -151,7 +150,7 @@ end:
  *
  *  Disabling event using the lttng API.
  */
-static int disable_events(char *session_name)
+static int disable_events(char *session_name, char *event_list)
 {
        int ret = CMD_SUCCESS, warn = 0, command_ret = CMD_SUCCESS;
        int enabled = 1, success = 1;
@@ -240,7 +239,7 @@ static int disable_events(char *session_name)
                }
        } else {
                /* Strip event list */
-               event_name = strtok(opt_event_list, ",");
+               event_name = strtok(event_list, ",");
                while (event_name != NULL) {
                        DBG("Disabling event %s", event_name);
 
@@ -318,6 +317,8 @@ int cmd_disable_events(int argc, const char **argv)
        int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
        static poptContext pc;
        char *session_name = NULL;
+       char *event_list = NULL;
+       const char *arg_event_list = NULL;
        const char *leftover = NULL;
        int event_type = -1;
 
@@ -384,13 +385,22 @@ int cmd_disable_events(int argc, const char **argv)
                goto end;
        }
 
-       opt_event_list = (char*) poptGetArg(pc);
-       if (opt_event_list == NULL && opt_disable_all == 0) {
+       arg_event_list = poptGetArg(pc);
+       if (arg_event_list == NULL && opt_disable_all == 0) {
                ERR("Missing event name(s).\n");
                ret = CMD_ERROR;
                goto end;
        }
 
+       if (opt_disable_all == 0) {
+               event_list = strdup(arg_event_list);
+               if (event_list == NULL) {
+                       PERROR("Failed to copy event name(s)");
+                       ret = CMD_ERROR;
+                       goto end;
+               }
+       }
+
        leftover = poptGetArg(pc);
        if (leftover) {
                ERR("Unknown argument: %s", leftover);
@@ -433,7 +443,7 @@ int cmd_disable_events(int argc, const char **argv)
                }
        }
 
-       command_ret = disable_events(session_name);
+       command_ret = disable_events(session_name, event_list);
        if (command_ret) {
                success = 0;
        }
@@ -467,6 +477,8 @@ end:
                free(session_name);
        }
 
+       free(event_list);
+
        /* Mi clean-up */
        if (writer && mi_lttng_writer_destroy(writer)) {
                /* Preserve original error code */
This page took 0.024112 seconds and 4 git commands to generate.