summaryrefslogtreecommitdiff
path: root/clone.go
diff options
context:
space:
mode:
authorlhchavez <[email protected]>2020-12-10 05:35:40 -0800
committerGitHub <[email protected]>2020-12-10 05:35:40 -0800
commite28cce87c7551bffa1f4602ff492348f9a8cba60 (patch)
tree17cda66f878bd6285f24d0867c444e9ca2e191e6 /clone.go
parentabf02bc7d79dfb7b0bbcd404ebecb202cff2a18e (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 'clone.go')
-rw-r--r--clone.go26
1 files changed, 12 insertions, 14 deletions
diff --git a/clone.go b/clone.go
index 8166b08..0f37a86 100644
--- a/clone.go
+++ b/clone.go
@@ -55,38 +55,36 @@ func Clone(url string, path string, options *CloneOptions) (*Repository, error)
//export remoteCreateCallback
func remoteCreateCallback(
- cremote unsafe.Pointer,
- crepo unsafe.Pointer,
+ out **C.git_remote,
+ crepo *C.git_repository,
cname, curl *C.char,
- payload unsafe.Pointer,
+ handle unsafe.Pointer,
) C.int {
name := C.GoString(cname)
url := C.GoString(curl)
- repo := newRepositoryFromC((*C.git_repository)(crepo))
- // We don't own this repository, so make sure we don't try to free it
- runtime.SetFinalizer(repo, nil)
+ repo := newRepositoryFromC(crepo)
+ repo.weak = true
+ defer repo.Free()
- data, ok := pointerHandles.Get(payload).(*cloneCallbackData)
+ data, ok := pointerHandles.Get(handle).(*cloneCallbackData)
if !ok {
panic("invalid remote create callback")
}
remote, ret := data.options.RemoteCreateCallback(repo, name, url)
- // clear finalizer as the calling C function will
- // free the remote itself
- runtime.SetFinalizer(remote, nil)
-
if ret < 0 {
*data.errorTarget = errors.New(ErrorCode(ret).String())
return C.int(ErrorCodeUser)
}
-
if remote == nil {
panic("no remote created by callback")
}
- cptr := (**C.git_remote)(cremote)
- *cptr = remote.ptr
+ *out = remote.ptr
+
+ // clear finalizer as the calling C function will
+ // free the remote itself
+ runtime.SetFinalizer(remote, nil)
return C.int(ErrorCodeOK)
}