Skip to content

Commit

Permalink
tools lib traceevent: Do not free tep->cmdlines in add_new_comm() on …
Browse files Browse the repository at this point in the history
…failure

[ Upstream commit e0d2615856b2046c2e8d5bfd6933f37f69703b0b ]

If the re-allocation of tep->cmdlines succeeds, then the previous
allocation of tep->cmdlines will be freed. If we later fail in
add_new_comm(), we must not free cmdlines, and also should assign
tep->cmdlines to the new allocation. Otherwise when freeing tep, the
tep->cmdlines will be pointing to garbage.

Fixes: a6d2a61 ("tools lib traceevent: Remove some die() calls")
Signed-off-by: Steven Rostedt (VMware) <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: [email protected]
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
Signed-off-by: Lee Jones <[email protected]>
Change-Id: I4cd068054b1ebf5a2826a54296cecae6bee786aa
  • Loading branch information
rostedt authored and Lee Jones committed Dec 20, 2019
1 parent 93805d2 commit 412cd14
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions tools/lib/traceevent/event-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ static int add_new_comm(struct pevent *pevent, const char *comm, int pid)
errno = ENOMEM;
return -1;
}
pevent->cmdlines = cmdlines;

cmdlines[pevent->cmdline_count].comm = strdup(comm);
if (!cmdlines[pevent->cmdline_count].comm) {
free(cmdlines);
errno = ENOMEM;
return -1;
}
Expand All @@ -278,7 +278,6 @@ static int add_new_comm(struct pevent *pevent, const char *comm, int pid)
pevent->cmdline_count++;

qsort(cmdlines, pevent->cmdline_count, sizeof(*cmdlines), cmdline_cmp);
pevent->cmdlines = cmdlines;

return 0;
}
Expand Down

0 comments on commit 412cd14

Please sign in to comment.