]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Plug minor memory leaks, mostly in unit tests
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 6 Feb 2016 16:12:34 +0000 (17:12 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 6 Feb 2016 16:12:34 +0000 (17:12 +0100)
ccache.c
test/test_argument_processing.c
test/test_conf.c
util.c

index d7eb87ef5d3dcb44b713fb00c3dc78398c4dac37..e75838c428707af4a7cb0f6311433a17e5e0b87f 100644 (file)
--- 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);
index 20ae65a07d79985718a8174d316528379b4aa09a..67f73718ef164f3b8707622862eda8d58bcb2e88 100644 (file)
@@ -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]);
index d6e3bc32af1718ad3de762011f3532306131fe33..b93dbdd10a6e1d2e0660115426b1be99b284640a 100644 (file)
@@ -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 6c89edae94abf006ab6ccf78060c4edb3dcdf41f..f0c7a5e17e188ad2d3bc275537e073ea08620f3c 100644 (file)
--- 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)
 {