diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2014-05-15 19:59:05 +0200 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2014-05-15 19:59:05 +0200 |
commit | 649214be4bd9d8239787e3af7e6d877955d09e11 (patch) | |
tree | 82992d2b31d8dc388574d59f011c0b24b5f378fe | |
parent | 4af0ef9690e9fdfc81afbeed7039d02a5f191001 (diff) | |
download | libgit2-cmn/pack-cache-init.tar.gz |
pack: init the cache on packfile alloccmn/pack-cache-init
When running multithreaded, it is not enough to check for the offmap
allocation. Move the call to cache_init() to packfile allocation so we
can be sure it is always allocated free of races.
This fixes #2355.
-rw-r--r-- | src/pack.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/pack.c b/src/pack.c index d93ee25f9..ace7abb58 100644 --- a/src/pack.c +++ b/src/pack.c @@ -83,16 +83,12 @@ static void cache_free(git_pack_cache *cache) } git_offmap_free(cache->entries); - git_mutex_free(&cache->lock); + cache->entries = NULL; } - - memset(cache, 0, sizeof(*cache)); } static int cache_init(git_pack_cache *cache) { - memset(cache, 0, sizeof(*cache)); - cache->entries = git_offmap_alloc(); GITERR_CHECK_ALLOC(cache->entries); @@ -534,9 +530,6 @@ static int pack_dependency_chain(git_dependency_chain *chain_out, size_t size, elem_pos; git_otype type; - if (!p->bases.entries && (cache_init(&p->bases) < 0)) - return -1; - elem_pos = 0; while (true) { struct pack_chain_elem *elem; @@ -985,6 +978,7 @@ void git_packfile_free(struct git_pack_file *p) git__free(p->bad_object_sha1); git_mutex_free(&p->lock); + git_mutex_free(&p->bases.lock); git__free(p); } @@ -1120,6 +1114,11 @@ int git_packfile_alloc(struct git_pack_file **pack_out, const char *path) return -1; } + if (cache_init(&p->bases) < 0) { + git__free(p); + return -1; + } + *pack_out = p; return 0; |