Fix SIGSEGV on double free for Cred object

This change removes the Go finalizer when passing ownership to libgit2.

Fixes: #553
(cherry picked from commit 0843b826d2)
This commit is contained in:
lhchavez 2020-03-26 17:50:12 -07:00
parent 0dfadb0dd0
commit 447d43c57d
1 changed files with 4 additions and 0 deletions

View File

@ -248,6 +248,10 @@ func credentialsCallback(_cred **C.git_cred, _url *C.char, _username_from_url *C
ret, cred := callbacks.CredentialsCallback(url, username_from_url, (CredType)(allowed_types)) ret, cred := callbacks.CredentialsCallback(url, username_from_url, (CredType)(allowed_types))
if cred != nil { if cred != nil {
*_cred = cred.ptr *_cred = cred.ptr
// have transferred ownership to libgit, 'forget' the native pointer
cred.ptr = nil
runtime.SetFinalizer(cred, nil)
} }
return int(ret) return int(ret)
} }