Fix memleak, TreeBuilder, Config and Parent commit #47
11
commit.go
11
commit.go
|
@ -9,8 +9,8 @@ extern int _go_git_treewalk(git_tree *tree, git_treewalk_mode mode, void *ptr);
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"unsafe"
|
|
||||||
"time"
|
"time"
|
||||||
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Commit
|
// Commit
|
||||||
|
@ -48,12 +48,13 @@ func (c Commit) Committer() *Signature {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Commit) Parent(n uint) *Commit {
|
func (c *Commit) Parent(n uint) *Commit {
|
||||||
par := &Commit{}
|
var cobj *C.git_object
|
||||||
ret := C.git_commit_parent(&par.ptr, c.ptr, C.uint(n))
|
ret := C.git_commit_parent(&cobj, c.ptr, C.uint(n))
|
||||||
if ret != 0 {
|
if ret != 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return par
|
|
||||||
|
return allocObject(cobj).(*Commit)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Commit) ParentId(n uint) *Oid {
|
func (c *Commit) ParentId(n uint) *Oid {
|
||||||
|
@ -88,7 +89,7 @@ func (v *Signature) Offset() int {
|
||||||
return offset / 60
|
return offset / 60
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sig *Signature) toC() (*C.git_signature) {
|
func (sig *Signature) toC() *C.git_signature {
|
||||||
var out *C.git_signature
|
var out *C.git_signature
|
||||||
|
|
||||||
name := C.CString(sig.Name)
|
name := C.CString(sig.Name)
|
||||||
|
|
|
@ -6,6 +6,7 @@ package git
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
|
"runtime"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -66,3 +67,8 @@ func (c *Config) Set(name, value string) (err error) {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Config) Free() {
|
||||||
|
runtime.SetFinalizer(c, nil)
|
||||||
|
C.git_config_free(c.ptr)
|
||||||
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@ package git
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"unsafe"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Repository
|
// Repository
|
||||||
|
@ -58,6 +58,7 @@ func (v *Repository) Config() (*Config, error) {
|
||||||
return nil, LastError()
|
return nil, LastError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runtime.SetFinalizer(config, (*Config).Free)
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,7 +227,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 +250,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
|
||||||
|
|
Loading…
Reference in New Issue