diff options
| author | lhchavez <[email protected]> | 2020-12-10 05:35:40 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-12-10 05:35:40 -0800 |
| commit | e28cce87c7551bffa1f4602ff492348f9a8cba60 (patch) | |
| tree | 17cda66f878bd6285f24d0867c444e9ca2e191e6 /repository.go | |
| parent | abf02bc7d79dfb7b0bbcd404ebecb202cff2a18e (diff) | |
Ensure that no pointer handles leak during the test (#712)
This change makes sure that pointer handles are correctly cleaned up
during tests.
Diffstat (limited to 'repository.go')
| -rw-r--r-- | repository.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/repository.go b/repository.go index f42f929..d2b9961 100644 --- a/repository.go +++ b/repository.go @@ -35,6 +35,10 @@ type Repository struct { // Stashes represents the collection of stashes and can be used to // save, apply and iterate over stash states in this repository. Stashes StashCollection + + // weak indicates that a repository is a weak pointer and should not be + // freed. + weak bool } func newRepositoryFromC(ptr *C.git_repository) *Repository { @@ -136,8 +140,13 @@ func (v *Repository) SetRefdb(refdb *Refdb) { } func (v *Repository) Free() { + ptr := v.ptr + v.ptr = nil runtime.SetFinalizer(v, nil) - C.git_repository_free(v.ptr) + if v.weak { + return + } + C.git_repository_free(ptr) } func (v *Repository) Config() (*Config, error) { |
