tree: keep tree receiver alive as long as dependent entry is used #430

Merged
sprohaska merged 1 commits from pr/keep-alive into master 2018-03-11 08:26:01 -05:00
1 changed files with 9 additions and 6 deletions

15
tree.go
View File

@ -52,12 +52,13 @@ func (t Tree) EntryByName(filename string) *TreeEntry {
defer C.free(unsafe.Pointer(cname)) defer C.free(unsafe.Pointer(cname))
entry := C.git_tree_entry_byname(t.cast_ptr, cname) entry := C.git_tree_entry_byname(t.cast_ptr, cname)
runtime.KeepAlive(t)
if entry == nil { if entry == nil {
return nil return nil
} }
return newTreeEntry(entry) goEntry := newTreeEntry(entry)
runtime.KeepAlive(t)
return goEntry
} }
// EntryById performs a lookup for a tree entry with the given SHA value. // EntryById performs a lookup for a tree entry with the given SHA value.
@ -71,13 +72,14 @@ func (t Tree) EntryById(id *Oid) *TreeEntry {
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
entry := C.git_tree_entry_byid(t.cast_ptr, id.toC()) entry := C.git_tree_entry_byid(t.cast_ptr, id.toC())
runtime.KeepAlive(t)
runtime.KeepAlive(id) runtime.KeepAlive(id)
if entry == nil { if entry == nil {
return nil return nil
} }
return newTreeEntry(entry) goEntry := newTreeEntry(entry)
runtime.KeepAlive(t)
return goEntry
} }
// EntryByPath looks up an entry by its full path, recursing into // EntryByPath looks up an entry by its full path, recursing into
@ -102,12 +104,13 @@ func (t Tree) EntryByPath(path string) (*TreeEntry, error) {
func (t Tree) EntryByIndex(index uint64) *TreeEntry { func (t Tree) EntryByIndex(index uint64) *TreeEntry {
entry := C.git_tree_entry_byindex(t.cast_ptr, C.size_t(index)) entry := C.git_tree_entry_byindex(t.cast_ptr, C.size_t(index))
runtime.KeepAlive(t)
if entry == nil { if entry == nil {
return nil return nil
} }
return newTreeEntry(entry) goEntry := newTreeEntry(entry)
runtime.KeepAlive(t)
return goEntry
} }
func (t Tree) EntryCount() uint64 { func (t Tree) EntryCount() uint64 {