Commit eb58e2d0 by Vicent Marti

Merge remote-tracking branch 'arrbee/minor-paranoia' into development

parents 3b5001b4 3e9e6cda
......@@ -66,9 +66,12 @@ void git_cache_dump_stats(git_cache *cache)
int git_cache_init(git_cache *cache)
{
cache->used_memory = 0;
memset(cache, 0, sizeof(*cache));
cache->map = git_oidmap_alloc();
git_mutex_init(&cache->lock);
if (git_mutex_init(&cache->lock)) {
giterr_set(GITERR_OS, "Failed to initialize cache mutex");
return -1;
}
return 0;
}
......@@ -102,9 +105,9 @@ void git_cache_clear(git_cache *cache)
void git_cache_free(git_cache *cache)
{
git_cache_clear(cache);
git_oidmap_free(cache->map);
git_mutex_free(&cache->lock);
git__memset(cache, 0, sizeof(*cache));
}
/* Called with lock */
......
......@@ -40,12 +40,14 @@ static void config_free(git_config *cfg)
size_t i;
file_internal *internal;
for(i = 0; i < cfg->files.length; ++i){
for (i = 0; i < cfg->files.length; ++i) {
internal = git_vector_get(&cfg->files, i);
GIT_REFCOUNT_DEC(internal, file_internal_free);
}
git_vector_free(&cfg->files);
git__memset(cfg, 0, sizeof(*cfg));
git__free(cfg);
}
......
......@@ -465,6 +465,8 @@ static void diff_list_free(git_diff_list *diff)
git_pathspec_free(&diff->pathspec);
git_pool_clear(&diff->pool);
git__memset(diff, 0, sizeof(*diff));
git__free(diff);
}
......
......@@ -61,7 +61,8 @@ int git_threads_init(void)
return 0;
_tls_index = TlsAlloc();
git_mutex_init(&git__mwindow_mutex);
if (git_mutex_init(&git__mwindow_mutex))
return -1;
/* Initialize any other subsystems that have global state */
if ((error = git_hash_global_init()) >= 0)
......@@ -121,7 +122,8 @@ int git_threads_init(void)
if (_tls_init)
return 0;
git_mutex_init(&git__mwindow_mutex);
if (git_mutex_init(&git__mwindow_mutex))
return -1;
pthread_key_create(&_tls_key, &cb__free_status);
/* Initialize any other subsystems that have global state */
......
......@@ -348,6 +348,8 @@ static void index_free(git_index *index)
git_vector_free(&index->reuc);
git__free(index->index_file_path);
git__memset(index, 0, sizeof(*index));
git__free(index);
}
......
......@@ -589,6 +589,8 @@ static void odb_free(git_odb *db)
git_vector_free(&db->backends);
git_cache_free(&db->own_cache);
git__memset(db, 0, sizeof(*db));
git__free(db);
}
......
......@@ -132,7 +132,10 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
if (git_mutex_init(&pb->cache_mutex) ||
git_mutex_init(&pb->progress_mutex) ||
git_cond_init(&pb->progress_cond))
{
giterr_set(GITERR_OS, "Failed to initialize packbuilder mutex");
goto on_error;
}
#endif
......
......@@ -85,15 +85,27 @@ static void cache_free(git_pack_cache *cache)
git_offmap_free(cache->entries);
git_mutex_free(&cache->lock);
}
memset(cache, 0, sizeof(*cache));
}
static int cache_init(git_pack_cache *cache)
{
memset(cache, 0, sizeof(git_pack_cache));
memset(cache, 0, sizeof(*cache));
cache->entries = git_offmap_alloc();
GITERR_CHECK_ALLOC(cache->entries);
cache->memory_limit = GIT_PACK_CACHE_MEMORY_LIMIT;
git_mutex_init(&cache->lock);
if (git_mutex_init(&cache->lock)) {
giterr_set(GITERR_OS, "Failed to initialize pack cache mutex");
git__free(cache->entries);
cache->entries = NULL;
return -1;
}
return 0;
}
......@@ -944,7 +956,11 @@ int git_packfile_alloc(struct git_pack_file **pack_out, const char *path)
p->mtime = (git_time_t)st.st_mtime;
p->index_version = -1;
git_mutex_init(&p->lock);
if (git_mutex_init(&p->lock)) {
giterr_set(GITERR_OS, "Failed to initialize packfile mutex");
git__free(p);
return -1;
}
/* see if we can parse the sha1 oid in the packfile name */
if (path_len < 40 ||
......
......@@ -89,6 +89,7 @@ int git_refdb_compress(git_refdb *db)
void git_refdb__free(git_refdb *db)
{
refdb_free_backend(db);
git__memset(db, 0, sizeof(*db));
git__free(db);
}
......
......@@ -119,6 +119,7 @@ void git_repository_free(git_repository *repo)
git__free(repo->workdir);
git__free(repo->namespace);
git__memset(repo, 0, sizeof(*repo));
git__free(repo);
}
......@@ -145,12 +146,10 @@ static bool valid_repository_path(git_buf *repository_path)
static git_repository *repository_alloc(void)
{
git_repository *repo = git__malloc(sizeof(git_repository));
git_repository *repo = git__calloc(1, sizeof(git_repository));
if (!repo)
return NULL;
memset(repo, 0x0, sizeof(git_repository));
if (git_cache_init(&repo->objects) < 0) {
git__free(repo);
return NULL;
......
......@@ -138,7 +138,7 @@ GIT_INLINE(int64_t) git_atomic64_add(git_atomic64 *a, int64_t addend)
/* Pthreads Mutex */
#define git_mutex unsigned int
#define git_mutex_init(a) (void)0
#define git_mutex_init(a) 0
#define git_mutex_lock(a) 0
#define git_mutex_unlock(a) (void)0
#define git_mutex_free(a) (void)0
......
......@@ -722,3 +722,13 @@ void git__insertsort_r(
if (freeswap)
git__free(swapel);
}
void git__memset(void *data, int c, size_t size)
{
volatile uint8_t *scan = data;
uint8_t *end = scan + size;
uint8_t val = (uint8_t)c;
while (scan < end)
*scan++ = val;
}
......@@ -295,8 +295,7 @@ GIT_INLINE(bool) git__iswildcard(int c)
}
/*
* Parse a string value as a boolean, just like Core Git
* does.
* Parse a string value as a boolean, just like Core Git does.
*
* Valid values for true are: 'true', 'yes', 'on'
* Valid values for false are: 'false', 'no', 'off'
......@@ -311,7 +310,7 @@ extern int git__parse_bool(int *out, const char *value);
* - "July 17, 2003"
* - "2003-7-17 08:23"
*/
int git__date_parse(git_time_t *out, const char *date);
extern int git__date_parse(git_time_t *out, const char *date);
/*
* Unescapes a string in-place.
......@@ -322,4 +321,10 @@ int git__date_parse(git_time_t *out, const char *date);
*/
extern size_t git__unescape(char *str);
/*
* Memset that will not be optimized away by the compiler.
* You usually should just use regular `memset()`.
*/
extern void git__memset(void *data, int c, size_t size);
#endif /* INCLUDE_util_h__ */
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