From e28cce87c7551bffa1f4602ff492348f9a8cba60 Mon Sep 17 00:00:00 2001 From: lhchavez Date: Thu, 10 Dec 2020 05:35:40 -0800 Subject: Ensure that no pointer handles leak during the test (#712) This change makes sure that pointer handles are correctly cleaned up during tests. --- reference.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'reference.go') diff --git a/reference.go b/reference.go index 524d7bb..e0c7cad 100644 --- a/reference.go +++ b/reference.go @@ -293,12 +293,14 @@ func (v *Reference) Peel(t ObjectType) (*Object, error) { return allocObject(cobj, v.repo), nil } -// Owner returns a weak reference to the repository which owns this -// reference. +// Owner returns a weak reference to the repository which owns this reference. +// This won't keep the underlying repository alive, but it should still be +// Freed. func (v *Reference) Owner() *Repository { - return &Repository{ - ptr: C.git_reference_owner(v.ptr), - } + repo := newRepositoryFromC(C.git_reference_owner(v.ptr)) + runtime.KeepAlive(v) + repo.weak = true + return repo } // Cmp compares v to ref2. It returns 0 on equality, otherwise a -- cgit v1.2.3