1
0
Fork 0
alistair23-linux/tools/lib/traceevent
Philippe Duplessis-Guindon 3429579045 tools lib traceevent: Fix memory leak in process_dynamic_array_len
[ Upstream commit e24c6447cc ]

I compiled with AddressSanitizer and I had these memory leaks while I
was using the tep_parse_format function:

    Direct leak of 28 byte(s) in 4 object(s) allocated from:
        #0 0x7fb07db49ffe in __interceptor_realloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dffe)
        #1 0x7fb07a724228 in extend_token /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:985
        #2 0x7fb07a724c21 in __read_token /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:1140
        #3 0x7fb07a724f78 in read_token /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:1206
        #4 0x7fb07a725191 in __read_expect_type /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:1291
        #5 0x7fb07a7251df in read_expect_type /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:1299
        #6 0x7fb07a72e6c8 in process_dynamic_array_len /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:2849
        #7 0x7fb07a7304b8 in process_function /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:3161
        #8 0x7fb07a730900 in process_arg_token /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:3207
        #9 0x7fb07a727c0b in process_arg /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:1786
        #10 0x7fb07a731080 in event_read_print_args /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:3285
        #11 0x7fb07a731722 in event_read_print /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:3369
        #12 0x7fb07a740054 in __tep_parse_format /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:6335
        #13 0x7fb07a74047a in __parse_event /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:6389
        #14 0x7fb07a740536 in tep_parse_format /home/pduplessis/repo/linux/tools/lib/traceevent/event-parse.c:6431
        #15 0x7fb07a785acf in parse_event ../../../src/fs-src/fs.c:251
        #16 0x7fb07a785ccd in parse_systems ../../../src/fs-src/fs.c:284
        #17 0x7fb07a786fb3 in read_metadata ../../../src/fs-src/fs.c:593
        #18 0x7fb07a78760e in ftrace_fs_source_init ../../../src/fs-src/fs.c:727
        #19 0x7fb07d90c19c in add_component_with_init_method_data ../../../../src/lib/graph/graph.c:1048
        #20 0x7fb07d90c87b in add_source_component_with_initialize_method_data ../../../../src/lib/graph/graph.c:1127
        #21 0x7fb07d90c92a in bt_graph_add_source_component ../../../../src/lib/graph/graph.c:1152
        #22 0x55db11aa632e in cmd_run_ctx_create_components_from_config_components ../../../src/cli/babeltrace2.c:2252
        #23 0x55db11aa6fda in cmd_run_ctx_create_components ../../../src/cli/babeltrace2.c:2347
        #24 0x55db11aa780c in cmd_run ../../../src/cli/babeltrace2.c:2461
        #25 0x55db11aa8a7d in main ../../../src/cli/babeltrace2.c:2673
        #26 0x7fb07d5460b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

The token variable in the process_dynamic_array_len function is
allocated in the read_expect_type function, but is not freed before
calling the read_token function.

Free the token variable before calling read_token in order to plug the
leak.

Signed-off-by: Philippe Duplessis-Guindon <pduplessis@efficios.com>
Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Link: https://lore.kernel.org/linux-trace-devel/20200730150236.5392-1-pduplessis@efficios.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-08-11 15:33:38 +02:00
..
Documentation libtraceevent: Man pages for tep plugins APIs 2019-09-25 09:51:43 -03:00
plugins libtraceevent: Fix build with binutils 2.35 2020-08-05 09:59:44 +02:00
.gitignore tools lib traceevent: Ignore generated library files 2016-08-02 12:16:13 -03:00
Build libtraceevent: Move traceevent plugins in its own subdirectory 2019-09-25 09:51:43 -03:00
Makefile libtraceevent: Copy pkg-config file to output folder when using O= 2020-01-12 12:21:14 +01:00
event-parse-api.c libtraceevent, perf tools: Changes in tep_print_event_* APIs 2019-08-31 22:19:28 -03:00
event-parse-local.h libtraceevent: Remove tep_register_trace_clock() 2019-08-31 22:19:28 -03:00
event-parse.c tools lib traceevent: Fix memory leak in process_dynamic_array_len 2020-08-11 15:33:38 +02:00
event-parse.h libtraceevent: Add tep_get_event() in event-parse.h 2019-09-25 09:51:43 -03:00
event-plugin.c libtraceevent: Change users plugin directory 2019-08-31 22:19:28 -03:00
event-utils.h tools lib traceevent: Change to SPDX License format 2018-08-20 08:54:58 -03:00
kbuffer-parse.c tools lib traceevent: Add more debugging to see various internal ring buffer entries 2019-04-01 15:18:09 -03:00
kbuffer.h tools lib traceevent: Add more debugging to see various internal ring buffer entries 2019-04-01 15:18:09 -03:00
libtraceevent.pc.template tools lib traceevent: Remove hard coded install paths from pkg-config file 2019-05-15 16:36:46 -03:00
parse-filter.c tools lib traceevent: Fix memory leakage in filter_event 2020-02-05 21:22:43 +00:00
parse-utils.c tools lib traceevent: Change tag string for error 2019-05-02 16:00:19 -04:00
tep_strerror.c tools lib traceevent: Separate out tep_strerror() for strerror_r() issues 2018-10-08 14:30:45 -03:00
trace-seq.c tools lib traceevent: Changed return logic of trace_seq_printf() and trace_seq_vprintf() APIs 2019-01-08 13:28:13 -03:00
trace-seq.h tools lib traceevent, perf tools: Split trace-seq related APIs in a separate header file 2018-08-30 15:52:20 -03:00