diff options
author | Steven Rostedt <srostedt@redhat.com> | 2011-02-24 21:41:58 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2011-02-24 21:41:58 -0500 |
commit | d9604ab0589a5c474be90ec62d842ad8504e50b0 (patch) | |
tree | fd0a8f030fcef3463de7e11db1f67872fbe98655 | |
parent | beef6f2839064af40ad6e5f27570a455d674a8ab (diff) |
trace-cmd: Close memory leaks in trace-output.c
Thanks again to valgrind.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | trace-output.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/trace-output.c b/trace-output.c index b6875dc..b91e1ac 100644 --- a/trace-output.c +++ b/trace-output.c | |||
@@ -448,9 +448,11 @@ static void glob_events(struct tracecmd_output *handle, | |||
448 | strcat(path, "/"); | 448 | strcat(path, "/"); |
449 | strcat(path, str); | 449 | strcat(path, str); |
450 | strcat(path, "/format"); | 450 | strcat(path, "/format"); |
451 | put_tracing_file(events_path); | ||
451 | 452 | ||
452 | globbuf.gl_offs = 0; | 453 | globbuf.gl_offs = 0; |
453 | ret = glob(path, 0, NULL, &globbuf); | 454 | ret = glob(path, 0, NULL, &globbuf); |
455 | free(path); | ||
454 | if (ret < 0) | 456 | if (ret < 0) |
455 | return; | 457 | return; |
456 | 458 | ||
@@ -479,6 +481,7 @@ static void glob_events(struct tracecmd_output *handle, | |||
479 | add_list_event_system(systems, system, event, file); | 481 | add_list_event_system(systems, system, event, file); |
480 | free(system); | 482 | free(system); |
481 | } | 483 | } |
484 | globfree(&globbuf); | ||
482 | } | 485 | } |
483 | 486 | ||
484 | static void | 487 | static void |
@@ -519,6 +522,7 @@ create_event_list_item(struct tracecmd_output *handle, | |||
519 | strcat(str, ptr); | 522 | strcat(str, ptr); |
520 | glob_events(handle, systems, str); | 523 | glob_events(handle, systems, str); |
521 | 524 | ||
525 | free(ptr); | ||
522 | free(str); | 526 | free(str); |
523 | } | 527 | } |
524 | 528 | ||
@@ -636,8 +640,8 @@ static int read_proc_kallsyms(struct tracecmd_output *handle, | |||
636 | static int read_ftrace_printk(struct tracecmd_output *handle) | 640 | static int read_ftrace_printk(struct tracecmd_output *handle) |
637 | { | 641 | { |
638 | unsigned int size, check_size, endian4; | 642 | unsigned int size, check_size, endian4; |
639 | const char *path; | ||
640 | struct stat st; | 643 | struct stat st; |
644 | char *path; | ||
641 | int ret; | 645 | int ret; |
642 | 646 | ||
643 | path = get_tracing_file(handle, "printk_formats"); | 647 | path = get_tracing_file(handle, "printk_formats"); |
@@ -650,21 +654,26 @@ static int read_ftrace_printk(struct tracecmd_output *handle) | |||
650 | size = 0; | 654 | size = 0; |
651 | endian4 = convert_endian_4(handle, size); | 655 | endian4 = convert_endian_4(handle, size); |
652 | if (do_write_check(handle, &endian4, 4)) | 656 | if (do_write_check(handle, &endian4, 4)) |
653 | return -1; | 657 | goto fail; |
654 | return 0; | 658 | goto out; |
655 | } | 659 | } |
656 | size = get_size(path); | 660 | size = get_size(path); |
657 | endian4 = convert_endian_4(handle, size); | 661 | endian4 = convert_endian_4(handle, size); |
658 | if (do_write_check(handle, &endian4, 4)) | 662 | if (do_write_check(handle, &endian4, 4)) |
659 | return -1; | 663 | goto fail; |
660 | check_size = copy_file(handle, path); | 664 | check_size = copy_file(handle, path); |
661 | if (size != check_size) { | 665 | if (size != check_size) { |
662 | errno = EINVAL; | 666 | errno = EINVAL; |
663 | warning("error in size of file '%s'", path); | 667 | warning("error in size of file '%s'", path); |
664 | return -1; | 668 | goto fail; |
665 | } | 669 | } |
666 | 670 | ||
671 | out: | ||
672 | put_tracing_file(path); | ||
667 | return 0; | 673 | return 0; |
674 | fail: | ||
675 | put_tracing_file(path); | ||
676 | return -1; | ||
668 | } | 677 | } |
669 | 678 | ||
670 | static struct tracecmd_output * | 679 | static struct tracecmd_output * |