Don't call the finalizer on a borrowed repository

When libgit2 gives us the repository for us to create the remote in, we
do not own it, so we must make sure we don't try to free it.
This commit is contained in:
Carlos Martín Nieto 2015-08-31 16:05:54 +02:00
parent 2743bbfca3
commit 4090c401c8
1 changed files with 5 additions and 4 deletions

View File

@ -55,15 +55,16 @@ func remoteCreateCallback(cremote unsafe.Pointer, crepo unsafe.Pointer, cname, c
name := C.GoString(cname) name := C.GoString(cname)
url := C.GoString(curl) url := C.GoString(curl)
repo := newRepositoryFromC((*C.git_repository)(crepo)) 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)
if opts, ok := pointerHandles.Get(payload).(CloneOptions); ok { if opts, ok := pointerHandles.Get(payload).(CloneOptions); ok {
remote, err := opts.RemoteCreateCallback(repo, name, url) remote, err := opts.RemoteCreateCallback(repo, name, url)
// clear finalizer as the calling C function will
// free the remote itself
runtime.SetFinalizer(remote, nil)
if err == ErrOk && remote != nil { if err == ErrOk && remote != nil {
// clear finalizer as the calling C function will
// free the remote itself
runtime.SetFinalizer(remote, nil)
cptr := (**C.git_remote)(cremote) cptr := (**C.git_remote)(cremote)
*cptr = remote.ptr *cptr = remote.ptr
} else if err == ErrOk && remote == nil { } else if err == ErrOk && remote == nil {