summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-05-31 14:09:58 -0700
committerRussell Belfer <rb@github.com>2013-05-31 14:09:58 -0700
commitf658dc433cae351e72b1c8b245724eafb43f5844 (patch)
tree025948ea3b6a30c41b44d86fe4655fbeda3d578c /src
parent17ef7dbce4e4eaa08ed7007b6d67f375759846a8 (diff)
downloadlibgit2-f658dc433cae351e72b1c8b245724eafb43f5844.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/cache.c4
-rw-r--r--src/config.c4
-rw-r--r--src/diff.c2
-rw-r--r--src/index.c2
-rw-r--r--src/odb.c2
-rw-r--r--src/pack.c6
-rw-r--r--src/refdb.c1
-rw-r--r--src/repository.c1
8 files changed, 18 insertions, 4 deletions
diff --git a/src/cache.c b/src/cache.c
index dc3af063a..6205ef8a9 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -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 */
diff --git a/src/config.c b/src/config.c
index 9491d267a..2c4b15540 100644
--- a/src/config.c
+++ b/src/config.c
@@ -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);
}
diff --git a/src/diff.c b/src/diff.c
index b96ff4705..f1d1010b4 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -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);
}
diff --git a/src/index.c b/src/index.c
index 45ce2f3d6..abc9495bd 100644
--- a/src/index.c
+++ b/src/index.c
@@ -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);
}
diff --git a/src/odb.c b/src/odb.c
index 9f18b5153..246f7d1ea 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -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);
}
diff --git a/src/pack.c b/src/pack.c
index 417d225f3..a9b835fca 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -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);
diff --git a/src/refdb.c b/src/refdb.c
index 9f9037ce7..02244c908 100644
--- a/src/refdb.c
+++ b/src/refdb.c
@@ -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);
}
diff --git a/src/repository.c b/src/repository.c
index 28505e822..8b16f00a4 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -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);
}