libgit2/tests-clar/network/createremotethenload.c
Sascha Cunz 9094d30b93 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
2012-11-23 11:41:56 +01:00

38 lines
1005 B
C

#include "clar_libgit2.h"
static git_remote *_remote;
static git_repository *_repo;
static git_config *_config;
static char url[] = "http://github.com/libgit2/libgit2.git";
void test_network_createremotethenload__initialize(void)
{
cl_fixture_sandbox("testrepo.git");
cl_git_pass(git_repository_open(&_repo, "testrepo.git"));
cl_git_pass(git_repository_config(&_config, _repo));
cl_git_pass(git_config_set_string(_config, "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*"));
cl_git_pass(git_config_set_string(_config, "remote.origin.url", url));
git_config_free(_config);
cl_git_pass(git_remote_load(&_remote, _repo, "origin"));
}
void test_network_createremotethenload__cleanup(void)
{
git_remote_free(_remote);
_remote = NULL;
git_repository_free(_repo);
_repo = NULL;
cl_fixture_cleanup("testrepo.git");
}
void test_network_createremotethenload__parsing(void)
{
cl_assert_equal_s(git_remote_name(_remote), "origin");
cl_assert_equal_s(git_remote_url(_remote), url);
}