Fix memleak for Config and parent commit objects

This commit is contained in:
Artiom Di 2013-11-14 15:24:43 +02:00
parent 295ec8894c
commit 5e30c192e9
3 changed files with 14 additions and 6 deletions

View File

@ -9,8 +9,8 @@ extern int _go_git_treewalk(git_tree *tree, git_treewalk_mode mode, void *ptr);
import "C"
import (
"unsafe"
"time"
"unsafe"
)
// Commit
@ -48,12 +48,13 @@ func (c Commit) Committer() *Signature {
}
func (c *Commit) Parent(n uint) *Commit {
par := &Commit{}
ret := C.git_commit_parent(&par.ptr, c.ptr, C.uint(n))
var cobj *C.git_object
ret := C.git_commit_parent(&cobj, c.ptr, C.uint(n))
if ret != 0 {
return nil
}
return par
return allocObject(cobj).(*Commit)
}
func (c *Commit) ParentId(n uint) *Oid {
@ -85,10 +86,10 @@ func newSignatureFromC(sig *C.git_signature) *Signature {
// the offset in mintes, which is what git wants
func (v *Signature) Offset() int {
_, offset := v.When.Zone()
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
name := C.CString(sig.Name)

View File

@ -6,6 +6,7 @@ package git
*/
import "C"
import (
"runtime"
"unsafe"
)
@ -66,3 +67,8 @@ func (c *Config) Set(name, value string) (err error) {
return nil
}
func (c *Config) Free() {
runtime.SetFinalizer(c, nil)
C.git_config_free(c.ptr)
}

View File

@ -58,6 +58,7 @@ func (v *Repository) Config() (*Config, error) {
return nil, LastError()
}
runtime.SetFinalizer(config, (*Config).Free)
return config, nil
}