Commit f658dc43 by Russell Belfer

Zero memory for major objects before freeing

By zeroing out the memory when we free larger objects (i.e. those
that serve as collections of other data, such as repos, odb, refdb),
I'm hoping that it will be easier for libgit2 bindings to find
errors in their object management code.
parent 17ef7dbc
......@@ -66,7 +66,7 @@ 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);
return 0;
......@@ -102,9 +102,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);
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);
memset(cfg, 0, sizeof(*cfg));
git__free(cfg);
}
......
......@@ -463,6 +463,8 @@ static void diff_list_free(git_diff_list *diff)
git_pathspec_free(&diff->pathspec);
git_pool_clear(&diff->pool);
memset(diff, 0, sizeof(*diff));
git__free(diff);
}
......
......@@ -348,6 +348,8 @@ static void index_free(git_index *index)
git_vector_free(&index->reuc);
git__free(index->index_file_path);
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);
memset(db, 0, sizeof(*db));
git__free(db);
}
......
......@@ -85,13 +85,17 @@ 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);
......
......@@ -89,6 +89,7 @@ int git_refdb_compress(git_refdb *db)
static void refdb_free(git_refdb *db)
{
refdb_free_backend(db);
memset(db, 0, sizeof(*db));
git__free(db);
}
......
......@@ -113,6 +113,7 @@ void git_repository_free(git_repository *repo)
git__free(repo->workdir);
git__free(repo->namespace);
memset(repo, 0, sizeof(*repo));
git__free(repo);
}
......
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