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 /clone.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 'clone.go')
| -rw-r--r-- | clone.go | 26 |
1 files changed, 12 insertions, 14 deletions
@@ -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) } |
