Commit fa399750 by Carlos Martín Nieto

Merge pull request #3265 from libgit2/leaks

Plug a bunch of leaks
parents 92ec9ed3 24fa21f3
...@@ -325,9 +325,14 @@ static int diff_binary(git_diff_output *output, git_patch *patch) ...@@ -325,9 +325,14 @@ static int diff_binary(git_diff_output *output, git_patch *patch)
old_data, old_len, new_data, new_len)) < 0) old_data, old_len, new_data, new_len)) < 0)
return error; return error;
return giterr_set_after_callback_function( error = giterr_set_after_callback_function(
output->binary_cb(patch->delta, &binary, output->payload), output->binary_cb(patch->delta, &binary, output->payload),
"git_patch"); "git_patch");
git__free((char *) binary.old_file.data);
git__free((char *) binary.new_file.data);
return error;
} }
static int diff_patch_generate(git_patch *patch, git_diff_output *output) static int diff_patch_generate(git_patch *patch, git_diff_output *output)
...@@ -377,6 +382,9 @@ static void diff_patch_free(git_patch *patch) ...@@ -377,6 +382,9 @@ static void diff_patch_free(git_patch *patch)
git__free((char *)patch->diff_opts.old_prefix); git__free((char *)patch->diff_opts.old_prefix);
git__free((char *)patch->diff_opts.new_prefix); git__free((char *)patch->diff_opts.new_prefix);
git__free((char *)patch->binary.old_file.data);
git__free((char *)patch->binary.new_file.data);
if (patch->flags & GIT_DIFF_PATCH_ALLOCATED) if (patch->flags & GIT_DIFF_PATCH_ALLOCATED)
git__free(patch); git__free(patch);
} }
......
...@@ -578,6 +578,9 @@ int git_diff_print( ...@@ -578,6 +578,9 @@ int git_diff_print(
giterr_set_after_callback_function(error, "git_diff_print"); giterr_set_after_callback_function(error, "git_diff_print");
} }
git__free(pi.nfile);
git__free(pi.ofile);
git_buf_free(&buf); git_buf_free(&buf);
return error; return error;
......
...@@ -1926,6 +1926,9 @@ int git_iterator_walk( ...@@ -1926,6 +1926,9 @@ int git_iterator_walk(
} }
done: done:
git__free(iterator_item);
git__free(cur_items);
if (error == GIT_ITEROVER) if (error == GIT_ITEROVER)
error = 0; error = 0;
......
...@@ -47,15 +47,19 @@ static int compare_file(void *payload, git_buf *actual_path) ...@@ -47,15 +47,19 @@ static int compare_file(void *payload, git_buf *actual_path)
git_buf expected_contents = GIT_BUF_INIT; git_buf expected_contents = GIT_BUF_INIT;
struct compare_data *cd = payload; struct compare_data *cd = payload;
bool failed = true; bool failed = true;
int cmp_git, cmp_gitattributes;
char *basename;
if (strcmp(git_path_basename(actual_path->ptr), ".git") == 0 || basename = git_path_basename(actual_path->ptr);
strcmp(git_path_basename(actual_path->ptr), ".gitattributes") == 0) { cmp_git = strcmp(basename, ".git");
cmp_gitattributes = strcmp(basename, ".gitattributes");
if (cmp_git == 0 || cmp_gitattributes == 0) {
failed = false; failed = false;
goto done; goto done;
} }
cl_git_pass(git_buf_joinpath(&expected_path, cd->dirname, cl_git_pass(git_buf_joinpath(&expected_path, cd->dirname, basename));
git_path_basename(actual_path->ptr)));
if (!git_path_isfile(expected_path.ptr) || if (!git_path_isfile(expected_path.ptr) ||
!git_path_isfile(actual_path->ptr)) !git_path_isfile(actual_path->ptr))
...@@ -83,6 +87,7 @@ done: ...@@ -83,6 +87,7 @@ done:
git_buf_free(&details); git_buf_free(&details);
} }
git__free(basename);
git_buf_free(&expected_contents); git_buf_free(&expected_contents);
git_buf_free(&actual_contents); git_buf_free(&actual_contents);
git_buf_free(&expected_path); git_buf_free(&expected_path);
...@@ -151,7 +156,12 @@ static void empty_workdir(const char *name) ...@@ -151,7 +156,12 @@ static void empty_workdir(const char *name)
git_path_dirload(&contents, name, 0, 0); git_path_dirload(&contents, name, 0, 0);
git_vector_foreach(&contents, i, fn) { git_vector_foreach(&contents, i, fn) {
if (strncasecmp(git_path_basename(fn), ".git", 4) == 0) char *basename = git_path_basename(fn);
int cmp = strncasecmp(basename, ".git", 4);
git__free(basename);
if (cmp == 0)
continue; continue;
p_unlink(fn); p_unlink(fn);
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "buffer.h" #include "buffer.h"
#include "filebuf.h" #include "filebuf.h"
#include "repository.h"
static git_repository *repo; static git_repository *repo;
...@@ -496,7 +497,7 @@ void test_diff_binary__blob_to_blob(void) ...@@ -496,7 +497,7 @@ void test_diff_binary__blob_to_blob(void)
opts.id_abbrev = GIT_OID_HEXSZ; opts.id_abbrev = GIT_OID_HEXSZ;
repo = cl_git_sandbox_init("renames"); repo = cl_git_sandbox_init("renames");
cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_repository_index__weakptr(&index, repo));
cl_git_append2file("renames/untimely.txt", "Oh that crazy Kipling!\r\n"); cl_git_append2file("renames/untimely.txt", "Oh that crazy Kipling!\r\n");
cl_git_pass(git_index_add_bypath(index, "untimely.txt")); cl_git_pass(git_index_add_bypath(index, "untimely.txt"));
...@@ -531,4 +532,7 @@ void test_diff_binary__blob_to_blob(void) ...@@ -531,4 +532,7 @@ void test_diff_binary__blob_to_blob(void)
git__free(diff_data.old_path); git__free(diff_data.old_path);
git__free(diff_data.new_path); git__free(diff_data.new_path);
git_buf_free(&diff_data.old_binary_base85);
git_buf_free(&diff_data.new_binary_base85);
} }
...@@ -394,4 +394,7 @@ void test_fetchhead_nonetwork__create_when_refpecs_given(void) ...@@ -394,4 +394,7 @@ void test_fetchhead_nonetwork__create_when_refpecs_given(void)
cl_git_pass(git_repository_fetchhead_foreach(g_repo, find_master, NULL)); cl_git_pass(git_repository_fetchhead_foreach(g_repo, find_master, NULL));
cl_assert(find_master_called); cl_assert(find_master_called);
cl_assert(found_master); cl_assert(found_master);
git_remote_free(remote);
git_buf_free(&path);
} }
...@@ -108,7 +108,7 @@ void test_index_racy__empty_file_after_smudge(void) ...@@ -108,7 +108,7 @@ void test_index_racy__empty_file_after_smudge(void)
const git_index_entry *entry; const git_index_entry *entry;
/* Make sure we do have a timestamp */ /* Make sure we do have a timestamp */
cl_git_pass(git_repository_index(&index, g_repo)); cl_git_pass(git_repository_index__weakptr(&index, g_repo));
cl_git_pass(git_index_write(index)); cl_git_pass(git_index_write(index));
cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "A")); cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "A"));
...@@ -140,4 +140,7 @@ void test_index_racy__empty_file_after_smudge(void) ...@@ -140,4 +140,7 @@ void test_index_racy__empty_file_after_smudge(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, index, NULL)); cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, index, NULL));
cl_assert_equal_i(1, git_diff_num_deltas(diff)); cl_assert_equal_i(1, git_diff_num_deltas(diff));
git_buf_free(&path);
git_diff_free(diff);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment