Fix memleak, free TreeBuilder

This commit is contained in:
Artiom Di 2013-11-14 13:08:34 +02:00
parent d8c3772e35
commit 295ec8894c
1 changed files with 4 additions and 3 deletions

View File

@ -6,8 +6,8 @@ package git
*/ */
import "C" import "C"
import ( import (
"unsafe"
"runtime" "runtime"
"unsafe"
) )
// Repository // Repository
@ -180,7 +180,7 @@ func (v *Repository) CreateCommit(
var cparents []*C.git_commit = nil var cparents []*C.git_commit = nil
var parentsarg **C.git_commit = nil var parentsarg **C.git_commit = nil
nparents:= len(parents) nparents := len(parents)
if nparents > 0 { if nparents > 0 {
cparents = make([]*C.git_commit, nparents) cparents = make([]*C.git_commit, nparents)
for i, v := range parents { for i, v := range parents {
@ -226,7 +226,7 @@ func (repo *Repository) Path() string {
return C.GoString(C.git_repository_path(repo.ptr)) return C.GoString(C.git_repository_path(repo.ptr))
} }
func (repo *Repository) IsBare() (bool) { func (repo *Repository) IsBare() bool {
return C.git_repository_is_bare(repo.ptr) != 0 return C.git_repository_is_bare(repo.ptr) != 0
} }
@ -249,6 +249,7 @@ func (v *Repository) TreeBuilder() (*TreeBuilder, error) {
if ret := C.git_treebuilder_create(&bld.ptr, nil); ret < 0 { if ret := C.git_treebuilder_create(&bld.ptr, nil); ret < 0 {
return nil, LastError() return nil, LastError()
} }
runtime.SetFinalizer(bld, (*TreeBuilder).Free)
bld.repo = v bld.repo = v
return bld, nil return bld, nil