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

Skip to content

Commit afd8a94

Browse files
committed
checkout: plug a few leaks
1 parent 9568660 commit afd8a94

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

tests/checkout/crlf.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,19 @@ static int compare_file(void *payload, git_buf *actual_path)
4747
git_buf expected_contents = GIT_BUF_INIT;
4848
struct compare_data *cd = payload;
4949
bool failed = true;
50+
int cmp_git, cmp_gitattributes;
51+
char *basename;
5052

51-
if (strcmp(git_path_basename(actual_path->ptr), ".git") == 0 ||
52-
strcmp(git_path_basename(actual_path->ptr), ".gitattributes") == 0) {
53+
basename = git_path_basename(actual_path->ptr);
54+
cmp_git = strcmp(basename, ".git");
55+
cmp_gitattributes = strcmp(basename, ".gitattributes");
56+
57+
if (cmp_git == 0 || cmp_gitattributes == 0) {
5358
failed = false;
5459
goto done;
5560
}
5661

57-
cl_git_pass(git_buf_joinpath(&expected_path, cd->dirname,
58-
git_path_basename(actual_path->ptr)));
62+
cl_git_pass(git_buf_joinpath(&expected_path, cd->dirname, basename));
5963

6064
if (!git_path_isfile(expected_path.ptr) ||
6165
!git_path_isfile(actual_path->ptr))
@@ -83,6 +87,7 @@ static int compare_file(void *payload, git_buf *actual_path)
8387
git_buf_free(&details);
8488
}
8589

90+
git__free(basename);
8691
git_buf_free(&expected_contents);
8792
git_buf_free(&actual_contents);
8893
git_buf_free(&expected_path);
@@ -151,7 +156,12 @@ static void empty_workdir(const char *name)
151156

152157
git_path_dirload(&contents, name, 0, 0);
153158
git_vector_foreach(&contents, i, fn) {
154-
if (strncasecmp(git_path_basename(fn), ".git", 4) == 0)
159+
char *basename = git_path_basename(fn);
160+
int cmp = strncasecmp(basename, ".git", 4);
161+
162+
git__free(basename);
163+
164+
if (cmp == 0)
155165
continue;
156166
p_unlink(fn);
157167
}

0 commit comments

Comments
 (0)