Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSascha Cunz <Sascha@BabbelBox.org>2012-11-23 14:41:56 +0400
committerSascha Cunz <Sascha@BabbelBox.org>2012-11-23 14:41:56 +0400
commit9094d30b932ca4b47dba81e76011efe05455a44a (patch)
tree117c53e9ad194d00274ad98e784318bd960c4053 /tests-clar/pack
parent5cf1b4f094eb6f724b27aa01d4f0481de2e673af (diff)
Reset all static variables to NULL in clar's __cleanup
Without this change, any failed assertion in the second (or a later) test inside a test suite has a chance of double deleting memory, resulting in a heap corruption. See #1096 for details. This leaves alone the test cases where we "just" use cl_git_sandbox_init() and cl_git_sandbox_cleanup(). These methods already take good care to not double delete a repository. Fixes #1096
Diffstat (limited to 'tests-clar/pack')
-rw-r--r--tests-clar/pack/packbuilder.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/tests-clar/pack/packbuilder.c b/tests-clar/pack/packbuilder.c
index 208141c27..1ec768d6b 100644
--- a/tests-clar/pack/packbuilder.c
+++ b/tests-clar/pack/packbuilder.c
@@ -7,6 +7,7 @@ static git_revwalk *_revwalker;
static git_packbuilder *_packbuilder;
static git_indexer *_indexer;
static git_vector _commits;
+static int _commits_is_initialized;
void test_pack_packbuilder__initialize(void)
{
@@ -14,6 +15,7 @@ void test_pack_packbuilder__initialize(void)
cl_git_pass(git_revwalk_new(&_revwalker, _repo));
cl_git_pass(git_packbuilder_new(&_packbuilder, _repo));
cl_git_pass(git_vector_init(&_commits, 0, NULL));
+ _commits_is_initialized = 1;
}
void test_pack_packbuilder__cleanup(void)
@@ -21,15 +23,25 @@ void test_pack_packbuilder__cleanup(void)
git_oid *o;
unsigned int i;
- git_vector_foreach(&_commits, i, o) {
- git__free(o);
+ if (_commits_is_initialized) {
+ _commits_is_initialized = 0;
+ git_vector_foreach(&_commits, i, o) {
+ git__free(o);
+ }
+ git_vector_free(&_commits);
}
- git_vector_free(&_commits);
+
git_packbuilder_free(_packbuilder);
+ _packbuilder = NULL;
+
git_revwalk_free(_revwalker);
+ _revwalker = NULL;
+
git_indexer_free(_indexer);
_indexer = NULL;
+
git_repository_free(_repo);
+ _repo = NULL;
}
static void seed_packbuilder(void)