From: Joel Rosdahl Date: Sat, 6 Feb 2016 16:12:34 +0000 (+0100) Subject: Plug minor memory leaks, mostly in unit tests X-Git-Tag: v3.3~120 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18ce49909a1d5785514d3e7336ae2c397da3ca96;p=thirdparty%2Fccache.git Plug minor memory leaks, mostly in unit tests --- diff --git a/ccache.c b/ccache.c index d7eb87ef5..e75838c42 100644 --- a/ccache.c +++ b/ccache.c @@ -696,6 +696,7 @@ make_relative_path(char *path) free(dir); return path; } + free(dir); path_suffix = basename(path); p = path; path = dirname(path); diff --git a/test/test_argument_processing.c b/test/test_argument_processing.c index 20ae65a07..67f73718e 100644 --- a/test/test_argument_processing.c +++ b/test/test_argument_processing.c @@ -125,6 +125,7 @@ TEST(sysroot_should_be_rewritten_if_basedir_is_used) current_working_dir = get_cwd(); arg_string = format("cc --sysroot=%s/foo -c foo.c", current_working_dir); orig = args_init_from_string(arg_string); + free(arg_string); CHECK(cc_process_args(orig, &act_cpp, &act_cc)); CHECK_STR_EQ(act_cpp->argv[1], "--sysroot=./foo"); @@ -260,12 +261,14 @@ TEST(fprofile_flag_with_existing_dir_should_be_rewritten_to_real_path) struct args *exp_cpp = args_init_from_string("gcc"); struct args *exp_cc = args_init_from_string("gcc"); struct args *act_cpp = NULL, *act_cc = NULL; - char *s; + char *s, *path; create_file("foo.c", ""); mkdir("some", 0777); mkdir("some/dir", 0777); - s = format("-fprofile-generate=%s", x_realpath("some/dir")); + path = x_realpath("some/dir"); + s = format("-fprofile-generate=%s", path); + free(path); args_add(exp_cpp, s); args_add(exp_cc, s); args_add(exp_cc, "-c"); @@ -310,6 +313,7 @@ TEST(isystem_flag_with_separate_arg_should_be_rewritten_if_basedir_is_used) current_working_dir = get_cwd(); arg_string = format("cc -isystem %s/foo -c foo.c", current_working_dir); orig = args_init_from_string(arg_string); + free(arg_string); CHECK(cc_process_args(orig, &act_cpp, &act_cc)); CHECK_STR_EQ("./foo", act_cpp->argv[2]); @@ -332,6 +336,7 @@ TEST(isystem_flag_with_concat_arg_should_be_rewritten_if_basedir_is_used) current_working_dir = get_cwd(); arg_string = format("cc -isystem%s/foo -c foo.c", current_working_dir); orig = args_init_from_string(arg_string); + free(arg_string); CHECK(cc_process_args(orig, &act_cpp, &act_cc)); CHECK_STR_EQ("-isystem", act_cpp->argv[1]); diff --git a/test/test_conf.c b/test/test_conf.c index d6e3bc32a..b93dbdd10 100644 --- a/test/test_conf.c +++ b/test/test_conf.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2014 Joel Rosdahl + * Copyright (C) 2011-2016 Joel Rosdahl * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free @@ -430,7 +430,7 @@ TEST(conf_print_items) for (i = 0; i < N_CONFIG_ITEMS; ++i) { char *expected = format("origin%zu", i); - CHECK_STR_EQ(expected, received_conf_items[i].origin); + CHECK_STR_EQ_FREE1(expected, received_conf_items[i].origin); } free_received_conf_items(); diff --git a/util.c b/util.c index 6c89edae9..f0c7a5e17 100644 --- a/util.c +++ b/util.c @@ -1079,7 +1079,7 @@ parse_size_with_suffix(const char *str, uint64_t *size) /* A sane realpath() function, trying to cope with stupid path limits and a - * broken API. */ + * broken API. Caller frees. */ char * x_realpath(const char *path) {