Fix: check malloc return value
[lttng-tools.git] / src / bin / lttng / commands / list.c
index 75862ffb4ba224cbc402cda0bb4c7a87625d6690..3e6445d69e6300176326620101c15c906d578d63 100644 (file)
@@ -71,7 +71,7 @@ static struct poptOption long_options[] = {
  */
 static void usage(FILE *ofp)
 {
-       fprintf(ofp, "usage: lttng list [OPTIONS] [SESSION [<OPTIONS>]]\n");
+       fprintf(ofp, "usage: lttng list [OPTIONS] [SESSION [SESSION OPTIONS]]\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "With no arguments, list available tracing session(s)\n");
        fprintf(ofp, "\n");
@@ -104,7 +104,7 @@ static char *get_cmdline_by_pid(pid_t pid)
        int ret;
        FILE *fp;
        char *cmdline = NULL;
-       char path[24];  /* Can't go bigger than /proc/65535/cmdline */
+       char path[20];  /* Can't go bigger than /proc/65535/cmdline */
 
        snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
        fp = fopen(path, "r");
@@ -114,6 +114,10 @@ static char *get_cmdline_by_pid(pid_t pid)
 
        /* Caller must free() *cmdline */
        cmdline = malloc(PATH_MAX);
+       if (!cmdline) {
+               perror("malloc cmdline");
+               goto end;
+       }
        ret = fread(cmdline, 1, PATH_MAX, fp);
        if (ret < 0) {
                perror("fread proc list");
@@ -407,6 +411,8 @@ static int list_ust_event_fields(void)
                        cmdline = get_cmdline_by_pid(cur_pid);
                        MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
                        free(cmdline);
+                       /* Wipe current event since we are about to print a new PID. */
+                       memset(&cur_event, 0, sizeof(cur_event));
                }
                if (strcmp(cur_event.name, event_field_list[i].event.name) != 0) {
                        print_events(&event_field_list[i].event);
@@ -799,7 +805,7 @@ int cmd_list(int argc, const char **argv)
                        goto end;
                }
 
-               if (opt_kernel) {
+               if (opt_kernel || opt_userspace) {
                        /* Channel listing */
                        ret = list_channels(opt_channel);
                        if (ret < 0) {
This page took 0.024208 seconds and 4 git commands to generate.