Commit 9cfce273 by Russell Belfer

Cleanups, renames, and leak fixes

This renames git_vector_free_all to the better git_vector_free_deep
and also contains a couple of memory leak fixes based on valgrind
checks.  The fixes are specifically: failure to free global dir
path variables when not compiled with threading on and failure to
free filters from the filter registry that had not be initialized
fully.
parent 11bd7a03
...@@ -149,6 +149,7 @@ typedef int (*git_filter_init_fn)(git_filter *self); ...@@ -149,6 +149,7 @@ typedef int (*git_filter_init_fn)(git_filter *self);
* Specified as `filter.shutdown`, this is an optional callback invoked * Specified as `filter.shutdown`, this is an optional callback invoked
* when the filter is unregistered or when libgit2 is shutting down. It * when the filter is unregistered or when libgit2 is shutting down. It
* will be called once at most and should release resources as needed. * will be called once at most and should release resources as needed.
* This may be called even if the `initialize` callback was not made.
* *
* Typically this function will free the `git_filter` object itself. * Typically this function will free the `git_filter` object itself.
*/ */
......
...@@ -139,7 +139,7 @@ void git_blame_free(git_blame *blame) ...@@ -139,7 +139,7 @@ void git_blame_free(git_blame *blame)
free_hunk(hunk); free_hunk(hunk);
git_vector_free(&blame->hunks); git_vector_free(&blame->hunks);
git_vector_free_all(&blame->paths); git_vector_free_deep(&blame->paths);
git_array_clear(blame->line_index); git_array_clear(blame->line_index);
......
...@@ -1765,7 +1765,7 @@ static void checkout_data_clear(checkout_data *data) ...@@ -1765,7 +1765,7 @@ static void checkout_data_clear(checkout_data *data)
git_vector_free(&data->removes); git_vector_free(&data->removes);
git_pool_clear(&data->pool); git_pool_clear(&data->pool);
git_vector_free_all(&data->conflicts); git_vector_free_deep(&data->conflicts);
git__free(data->pfx); git__free(data->pfx);
data->pfx = NULL; data->pfx = NULL;
......
...@@ -476,7 +476,7 @@ static int diff_list_apply_options( ...@@ -476,7 +476,7 @@ static int diff_list_apply_options(
static void diff_list_free(git_diff *diff) static void diff_list_free(git_diff *diff)
{ {
git_vector_free_all(&diff->deltas); git_vector_free_deep(&diff->deltas);
git_pathspec__vfree(&diff->pathspec); git_pathspec__vfree(&diff->pathspec);
git_pool_clear(&diff->pool); git_pool_clear(&diff->pool);
......
...@@ -209,7 +209,7 @@ int git_diff_merge(git_diff *onto, const git_diff *from) ...@@ -209,7 +209,7 @@ int git_diff_merge(git_diff *onto, const git_diff *from)
git_pool_strdup_safe(&onto->pool, onto->opts.new_prefix); git_pool_strdup_safe(&onto->pool, onto->opts.new_prefix);
} }
git_vector_free_all(&onto_new); git_vector_free_deep(&onto_new);
git_pool_clear(&onto_pool); git_pool_clear(&onto_pool);
return error; return error;
...@@ -440,7 +440,7 @@ static int apply_splits_and_deletes( ...@@ -440,7 +440,7 @@ static int apply_splits_and_deletes(
return 0; return 0;
on_error: on_error:
git_vector_free_all(&onto); git_vector_free_deep(&onto);
return -1; return -1;
} }
......
...@@ -615,6 +615,8 @@ static git_futils_dirs_guess_cb git_futils__dir_guess[GIT_FUTILS_DIR__MAX] = { ...@@ -615,6 +615,8 @@ static git_futils_dirs_guess_cb git_futils__dir_guess[GIT_FUTILS_DIR__MAX] = {
git_futils_guess_template_dirs, git_futils_guess_template_dirs,
}; };
static int git_futils__dirs_shutdown_set = 0;
void git_futils_dirs_global_shutdown(void) void git_futils_dirs_global_shutdown(void)
{ {
int i; int i;
...@@ -631,8 +633,6 @@ int git_futils_dirs_global_init(void) ...@@ -631,8 +633,6 @@ int git_futils_dirs_global_init(void)
for (i = 0; !error && i < GIT_FUTILS_DIR__MAX; i++) for (i = 0; !error && i < GIT_FUTILS_DIR__MAX; i++)
error = git_futils_dirs_get(&path, i); error = git_futils_dirs_get(&path, i);
git__on_shutdown(git_futils_dirs_global_shutdown);
return error; return error;
} }
...@@ -652,9 +652,16 @@ int git_futils_dirs_get(const git_buf **out, git_futils_dir_t which) ...@@ -652,9 +652,16 @@ int git_futils_dirs_get(const git_buf **out, git_futils_dir_t which)
GITERR_CHECK_ERROR(git_futils_check_selector(which)); GITERR_CHECK_ERROR(git_futils_check_selector(which));
if (!git_buf_len(&git_futils__dirs[which])) if (!git_buf_len(&git_futils__dirs[which])) {
/* prepare shutdown if we're going to need it */
if (!git_futils__dirs_shutdown_set) {
git__on_shutdown(git_futils_dirs_global_shutdown);
git_futils__dirs_shutdown_set = 1;
}
GITERR_CHECK_ERROR( GITERR_CHECK_ERROR(
git_futils__dir_guess[which](&git_futils__dirs[which])); git_futils__dir_guess[which](&git_futils__dirs[which]));
}
*out = &git_futils__dirs[which]; *out = &git_futils__dirs[which];
return 0; return 0;
......
...@@ -69,7 +69,7 @@ static void filter_registry_shutdown(void) ...@@ -69,7 +69,7 @@ static void filter_registry_shutdown(void)
return; return;
git_vector_foreach(&reg->filters, pos, fdef) { git_vector_foreach(&reg->filters, pos, fdef) {
if (fdef->initialized && fdef->filter && fdef->filter->shutdown) { if (fdef->filter && fdef->filter->shutdown) {
fdef->filter->shutdown(fdef->filter); fdef->filter->shutdown(fdef->filter);
fdef->initialized = false; fdef->initialized = false;
} }
......
...@@ -1010,7 +1010,7 @@ void git_indexer_free(git_indexer *idx) ...@@ -1010,7 +1010,7 @@ void git_indexer_free(git_indexer *idx)
if (idx == NULL) if (idx == NULL)
return; return;
git_vector_free_all(&idx->objects); git_vector_free_deep(&idx->objects);
if (idx->pack) { if (idx->pack) {
struct git_pack_entry *pentry; struct git_pack_entry *pentry;
...@@ -1020,7 +1020,7 @@ void git_indexer_free(git_indexer *idx) ...@@ -1020,7 +1020,7 @@ void git_indexer_free(git_indexer *idx)
git_oidmap_free(idx->pack->idx_cache); git_oidmap_free(idx->pack->idx_cache);
} }
git_vector_free_all(&idx->deltas); git_vector_free_deep(&idx->deltas);
git_packfile_free(idx->pack); git_packfile_free(idx->pack);
git_filebuf_cleanup(&idx->pack_file); git_filebuf_cleanup(&idx->pack_file);
git__free(idx); git__free(idx);
......
...@@ -920,7 +920,7 @@ static fs_iterator_frame *fs_iterator__alloc_frame(fs_iterator *fi) ...@@ -920,7 +920,7 @@ static fs_iterator_frame *fs_iterator__alloc_frame(fs_iterator *fi)
static void fs_iterator__free_frame(fs_iterator_frame *ff) static void fs_iterator__free_frame(fs_iterator_frame *ff)
{ {
git_vector_free_all(&ff->entries); git_vector_free_deep(&ff->entries);
git__free(ff); git__free(ff);
} }
......
...@@ -2383,7 +2383,7 @@ done: ...@@ -2383,7 +2383,7 @@ done:
git_index_set_caps(index_repo, index_repo_caps); git_index_set_caps(index_repo, index_repo_caps);
git_index_free(index_repo); git_index_free(index_repo);
git_vector_free_all(&paths); git_vector_free_deep(&paths);
return error; return error;
} }
......
...@@ -102,7 +102,7 @@ int git_pathspec__vinit( ...@@ -102,7 +102,7 @@ int git_pathspec__vinit(
/* free data from the pathspec vector */ /* free data from the pathspec vector */
void git_pathspec__vfree(git_vector *vspec) void git_pathspec__vfree(git_vector *vspec)
{ {
git_vector_free_all(vspec); git_vector_free_deep(vspec);
} }
struct pathspec_match_context { struct pathspec_match_context {
......
...@@ -541,7 +541,7 @@ static int queue_objects(git_push *push) ...@@ -541,7 +541,7 @@ static int queue_objects(git_push *push)
error = 0; error = 0;
on_error: on_error:
git_vector_free_all(&commits); git_vector_free_deep(&commits);
return error; return error;
} }
......
...@@ -1138,7 +1138,7 @@ int git_remote_list(git_strarray *remotes_list, git_repository *repo) ...@@ -1138,7 +1138,7 @@ int git_remote_list(git_strarray *remotes_list, git_repository *repo)
cfg, "^remote\\..*\\.(push)?url$", remote_list_cb, &list); cfg, "^remote\\..*\\.(push)?url$", remote_list_cb, &list);
if (error < 0) { if (error < 0) {
git_vector_free_all(&list); git_vector_free_deep(&list);
return error; return error;
} }
...@@ -1617,7 +1617,7 @@ static int copy_refspecs(git_strarray *array, git_remote *remote, unsigned int p ...@@ -1617,7 +1617,7 @@ static int copy_refspecs(git_strarray *array, git_remote *remote, unsigned int p
return 0; return 0;
on_error: on_error:
git_vector_free_all(&refspecs); git_vector_free_deep(&refspecs);
return -1; return -1;
} }
......
...@@ -367,7 +367,7 @@ void git_status_list_free(git_status_list *status) ...@@ -367,7 +367,7 @@ void git_status_list_free(git_status_list *status)
git_diff_free(status->head2idx); git_diff_free(status->head2idx);
git_diff_free(status->idx2wd); git_diff_free(status->idx2wd);
git_vector_free_all(&status->paired); git_vector_free_deep(&status->paired);
git__memzero(status, sizeof(*status)); git__memzero(status, sizeof(*status));
git__free(status); git__free(status);
......
...@@ -404,7 +404,7 @@ static void clear_parser_state(http_subtransport *t) ...@@ -404,7 +404,7 @@ static void clear_parser_state(http_subtransport *t)
git__free(t->location); git__free(t->location);
t->location = NULL; t->location = NULL;
git_vector_free_all(&t->www_authenticate); git_vector_free_deep(&t->www_authenticate);
} }
static int write_chunk(gitno_socket *socket, const char *buffer, size_t len) static int write_chunk(gitno_socket *socket, const char *buffer, size_t len)
......
...@@ -77,7 +77,7 @@ void git_vector_free(git_vector *v) ...@@ -77,7 +77,7 @@ void git_vector_free(git_vector *v)
v->_alloc_size = 0; v->_alloc_size = 0;
} }
void git_vector_free_all(git_vector *v) void git_vector_free_deep(git_vector *v)
{ {
size_t i; size_t i;
......
...@@ -23,7 +23,7 @@ typedef struct git_vector { ...@@ -23,7 +23,7 @@ typedef struct git_vector {
int git_vector_init(git_vector *v, size_t initial_size, git_vector_cmp cmp); int git_vector_init(git_vector *v, size_t initial_size, git_vector_cmp cmp);
void git_vector_free(git_vector *v); void git_vector_free(git_vector *v);
void git_vector_free_all(git_vector *v); /* free each entry and self */ void git_vector_free_deep(git_vector *v); /* free each entry and self */
void git_vector_clear(git_vector *v); void git_vector_clear(git_vector *v);
int git_vector_dup(git_vector *v, const git_vector *src, git_vector_cmp cmp); int git_vector_dup(git_vector *v, const git_vector *src, git_vector_cmp cmp);
void git_vector_swap(git_vector *a, git_vector *b); void git_vector_swap(git_vector *a, git_vector *b);
......
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