Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 17442b2

Browse files
author
Edward Thomson
committed
leaks: fix some leaks in the tests
1 parent 9705483 commit 17442b2

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

tests/config/write.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,10 +712,13 @@ void test_config_write__repeated(void)
712712
cl_git_pass(git_config_set_string(cfg, "sample.prefix.setting2", "someValue2"));
713713
cl_git_pass(git_config_set_string(cfg, "sample.prefix.setting3", "someValue3"));
714714
cl_git_pass(git_config_set_string(cfg, "sample.prefix.setting4", "someValue4"));
715+
git_config_free(cfg);
715716

716717
cl_git_pass(git_config_open_ondisk(&cfg, filename));
717718

718719
cl_git_pass(git_futils_readbuffer(&result, filename));
719720
cl_assert_equal_s(expected, result.ptr);
720721
git_buf_free(&result);
722+
723+
git_config_free(cfg);
721724
}

tests/iterator/index.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,9 @@ void test_iterator_index__pathlist_with_directory(void)
970970
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
971971
expect_iterator_items(i, 4, NULL, 4, NULL);
972972
git_iterator_free(i);
973+
973974
git_index_free(index);
975+
git_tree_free(tree);
974976
git_vector_free(&filelist);
975977
}
976978

tests/iterator/tree.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,7 @@ void test_iterator_tree__pathlist_with_directory(void)
10201020
expect_iterator_items(i, expected_len2, expected2, expected_len2, expected2);
10211021
git_iterator_free(i);
10221022

1023+
git_tree_free(tree);
10231024
git_vector_free(&filelist);
10241025
}
10251026

@@ -1048,6 +1049,7 @@ void test_iterator_tree__pathlist_with_directory_include_tree_nodes(void)
10481049
expect_iterator_items(i, expected_len, expected, expected_len, expected);
10491050
git_iterator_free(i);
10501051

1052+
git_tree_free(tree);
10511053
git_vector_free(&filelist);
10521054
}
10531055

@@ -1070,7 +1072,9 @@ void test_iterator_tree__pathlist_no_match(void)
10701072

10711073
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
10721074
cl_assert_equal_i(GIT_ITEROVER, git_iterator_current(&entry, i));
1075+
git_iterator_free(i);
10731076

1077+
git_tree_free(tree);
10741078
git_vector_free(&filelist);
10751079
}
10761080

tests/iterator/workdir.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,8 @@ static void create_paths(const char *root, int depth)
10301030
create_paths(fullpath.ptr, (depth - 1));
10311031
}
10321032
}
1033+
1034+
git_buf_free(&fullpath);
10331035
}
10341036

10351037
void test_iterator_workdir__pathlist_for_deeply_nested_item(void)

tests/status/worktree.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,15 +1211,15 @@ void test_status_worktree__with_directory_in_pathlist(void)
12111211
const git_status_entry *status;
12121212
size_t i, entrycount;
12131213
bool native_ignore_case;
1214+
char *subdir_path = "subdir";
12141215

12151216
cl_git_pass(git_repository_index(&index, repo));
12161217
native_ignore_case =
12171218
(git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0;
12181219
git_index_free(index);
12191220

1221+
opts.pathspec.strings = &subdir_path;
12201222
opts.pathspec.count = 1;
1221-
opts.pathspec.strings = malloc(opts.pathspec.count * sizeof(char *));
1222-
opts.pathspec.strings[0] = "subdir";
12231223
opts.flags =
12241224
GIT_STATUS_OPT_DEFAULTS |
12251225
GIT_STATUS_OPT_INCLUDE_UNMODIFIED |
@@ -1240,6 +1240,8 @@ void test_status_worktree__with_directory_in_pathlist(void)
12401240
status->index_to_workdir->old_file.path);
12411241
}
12421242

1243+
git_status_list_free(statuslist);
1244+
12431245
opts.show = GIT_STATUS_SHOW_INDEX_ONLY;
12441246
git_status_list_new(&statuslist, repo, &opts);
12451247

@@ -1255,6 +1257,8 @@ void test_status_worktree__with_directory_in_pathlist(void)
12551257
status->head_to_index->old_file.path);
12561258
}
12571259

1260+
git_status_list_free(statuslist);
1261+
12581262
opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
12591263
git_status_list_new(&statuslist, repo, &opts);
12601264

@@ -1269,5 +1273,7 @@ void test_status_worktree__with_directory_in_pathlist(void)
12691273
testrepo2_subdir_paths[i],
12701274
status->index_to_workdir->old_file.path);
12711275
}
1276+
1277+
git_status_list_free(statuslist);
12721278
}
12731279

0 commit comments

Comments
 (0)