Fix warnings and valgrind issues

This fixes some various warnings that showed up in Travis and
a couple uses of uninitialized memory and one memory leak.
This commit is contained in:
Russell Belfer 2012-11-09 14:01:44 -08:00
parent 0f3def715d
commit 757b406504
7 changed files with 17 additions and 11 deletions

View File

@ -432,8 +432,8 @@ static int checkout_get_actions(
int error; int error;
git_diff_list *diff = data->diff; git_diff_list *diff = data->diff;
git_diff_delta *delta; git_diff_delta *delta;
size_t i, *counts; size_t i, *counts = NULL;
uint32_t *actions; uint32_t *actions = NULL;
git_tree *head = NULL; git_tree *head = NULL;
git_iterator *hiter = NULL; git_iterator *hiter = NULL;
char *pfx = git_pathspec_prefix(&data->opts->paths); char *pfx = git_pathspec_prefix(&data->opts->paths);
@ -456,6 +456,7 @@ static int checkout_get_actions(
goto fail; goto fail;
git__free(pfx); git__free(pfx);
pfx = NULL;
*counts_ptr = counts = git__calloc(CHECKOUT_ACTION__MAX+1, sizeof(size_t)); *counts_ptr = counts = git__calloc(CHECKOUT_ACTION__MAX+1, sizeof(size_t));
*actions_ptr = actions = git__calloc(diff->deltas.length, sizeof(uint32_t)); *actions_ptr = actions = git__calloc(diff->deltas.length, sizeof(uint32_t));
@ -509,6 +510,8 @@ static int checkout_get_actions(
} }
git_iterator_free(hiter); git_iterator_free(hiter);
git_tree_free(head);
return 0; return 0;
fail: fail:
@ -518,6 +521,7 @@ fail:
git__free(actions); git__free(actions);
git_iterator_free(hiter); git_iterator_free(hiter);
git_tree_free(head);
git__free(pfx); git__free(pfx);
return -1; return -1;

View File

@ -402,7 +402,7 @@ int git_index_read(git_index *index)
{ {
int error = 0, updated; int error = 0, updated;
git_buf buffer = GIT_BUF_INIT; git_buf buffer = GIT_BUF_INIT;
git_futils_filestamp stamp; git_futils_filestamp stamp = {0};
if (!index->index_file_path) { if (!index->index_file_path) {
giterr_set(GITERR_INDEX, giterr_set(GITERR_INDEX,

View File

@ -73,16 +73,16 @@ static int packbuilder_config(git_packbuilder *pb)
{ {
git_config *config; git_config *config;
int ret; int ret;
int64_t val;
if (git_repository_config__weakptr(&config, pb->repo) < 0) if (git_repository_config__weakptr(&config, pb->repo) < 0)
return -1; return -1;
#define config_get(key, dst, default) \ #define config_get(KEY,DST,DFLT) do { \
ret = git_config_get_int64((int64_t *)&dst, config, key); \ ret = git_config_get_int64(&val, config, KEY); \
if (ret == GIT_ENOTFOUND) \ if (!ret) (DST) = val; \
dst = default; \ else if (ret == GIT_ENOTFOUND) (DST) = (DFLT); \
else if (ret < 0) \ else if (ret < 0) return -1; } while (0)
return -1;
config_get("pack.deltaCacheSize", pb->max_delta_cache_size, config_get("pack.deltaCacheSize", pb->max_delta_cache_size,
GIT_PACK_DELTA_CACHE_SIZE); GIT_PACK_DELTA_CACHE_SIZE);

View File

@ -629,6 +629,8 @@ int git_smart_subtransport_http(git_smart_subtransport **out,
http_subtransport *t; http_subtransport *t;
int flags; int flags;
(void)flags;
if (!out) if (!out)
return -1; return -1;

View File

@ -113,7 +113,7 @@ void test_clone_network__can_checkout_a_cloned_repo(void)
bool checkout_progress_cb_was_called = false, bool checkout_progress_cb_was_called = false,
fetch_progress_cb_was_called = false; fetch_progress_cb_was_called = false;
opts.checkout_strategy = GIT_CHECKOUT_UPDATE_UNMODIFIED; opts.checkout_strategy = GIT_CHECKOUT_SAFE;
opts.progress_cb = &checkout_progress; opts.progress_cb = &checkout_progress;
opts.progress_payload = &checkout_progress_cb_was_called; opts.progress_payload = &checkout_progress_cb_was_called;

View File

@ -62,7 +62,6 @@ void test_config_configlevel__fetching_a_level_from_an_empty_compound_config_ret
{ {
git_config *cfg; git_config *cfg;
git_config *local_cfg; git_config *local_cfg;
const char *s;
cl_git_pass(git_config_new(&cfg)); cl_git_pass(git_config_new(&cfg));

View File

@ -16,6 +16,7 @@ void commit_staged_files(
cl_git_pass(git_index_write_tree(&tree_oid, index)); cl_git_pass(git_index_write_tree(&tree_oid, index));
cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid)); cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid));
cl_git_pass(git_commit_create_v( cl_git_pass(git_commit_create_v(
commit_oid, commit_oid,
repo, repo,