Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools lib traceevent: Copy trace_clock and free it

The pevent->trace_clock should not be a direct pointer to what was
given. It should be copied and freed.

Note, valgrind pointed this out when a caller passed in a pointer that
needed to be freed and it never was. Ideally, pevent should copy it
(which this change does), and free the copy. It's up to the caller to
free the clock string passed in.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20150324135922.695906738@goodmis.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Steven Rostedt (Red Hat) and committed by
Arnaldo Carvalho de Melo
99ad1417 deab6f55

+9 -3
+8 -2
tools/lib/traceevent/event-parse.c
··· 321 321 return 0; 322 322 } 323 323 324 - void pevent_register_trace_clock(struct pevent *pevent, char *trace_clock) 324 + int pevent_register_trace_clock(struct pevent *pevent, const char *trace_clock) 325 325 { 326 - pevent->trace_clock = trace_clock; 326 + pevent->trace_clock = strdup(trace_clock); 327 + if (!pevent->trace_clock) { 328 + errno = ENOMEM; 329 + return -1; 330 + } 331 + return 0; 327 332 } 328 333 329 334 struct func_map { ··· 6357 6352 free_handler(handle); 6358 6353 } 6359 6354 6355 + free(pevent->trace_clock); 6360 6356 free(pevent->events); 6361 6357 free(pevent->sort_events); 6362 6358
+1 -1
tools/lib/traceevent/event-parse.h
··· 599 599 }; 600 600 601 601 int pevent_register_comm(struct pevent *pevent, const char *comm, int pid); 602 - void pevent_register_trace_clock(struct pevent *pevent, char *trace_clock); 602 + int pevent_register_trace_clock(struct pevent *pevent, const char *trace_clock); 603 603 int pevent_register_function(struct pevent *pevent, char *name, 604 604 unsigned long long addr, char *mod); 605 605 int pevent_register_print_string(struct pevent *pevent, const char *fmt,