Fix a memory leak in Index.EntryByPath()

This commit is contained in:
FUJII Ryota 2015-12-16 16:37:50 +09:00
parent 749963ce55
commit 1cdf1d70a2
1 changed files with 4 additions and 1 deletions

View File

@ -350,10 +350,13 @@ func (v *Index) EntryByIndex(index uint) (*IndexEntry, error) {
} }
func (v *Index) EntryByPath(path string, stage int) (*IndexEntry, error) { func (v *Index) EntryByPath(path string, stage int) (*IndexEntry, error) {
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))
runtime.LockOSThread() runtime.LockOSThread()
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
centry := C.git_index_get_bypath(v.ptr, C.CString(path), C.int(stage)) centry := C.git_index_get_bypath(v.ptr, cpath, C.int(stage))
if centry == nil { if centry == nil {
return nil, MakeGitError(C.GIT_ENOTFOUND) return nil, MakeGitError(C.GIT_ENOTFOUND)
} }