summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Martí <[email protected]>2013-11-18 07:24:37 -0800
committerVicent Martí <[email protected]>2013-11-18 07:24:37 -0800
commit625ffd022e2c39f3820543cc1239deeb21837266 (patch)
treed82a9bc90cb9198ff2f9d1cb893eb530387fcde9
parentd8c3772e350f387bb55b74dc1d654d69bd66b69a (diff)
parent5e30c192e9f7219322887da7252c344d5be1ec05 (diff)
Merge pull request #47 from kron4eg/tree_builder_mem_leak
Fix memleak, TreeBuilder, Config and Parent commit
-rw-r--r--commit.go13
-rw-r--r--config.go6
-rw-r--r--repository.go8
3 files changed, 18 insertions, 9 deletions
diff --git a/commit.go b/commit.go
index cacaa33..c633e2d 100644
--- a/commit.go
+++ b/commit.go
@@ -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)
diff --git a/config.go b/config.go
index dcad2a7..7235716 100644
--- a/config.go
+++ b/config.go
@@ -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)
+}
diff --git a/repository.go b/repository.go
index 34df0aa..5540a0c 100644
--- a/repository.go
+++ b/repository.go
@@ -6,8 +6,8 @@ package git
*/
import "C"
import (
- "unsafe"
"runtime"
+ "unsafe"
)
// Repository
@@ -58,6 +58,7 @@ func (v *Repository) Config() (*Config, error) {
return nil, LastError()
}
+ runtime.SetFinalizer(config, (*Config).Free)
return config, nil
}
@@ -180,7 +181,7 @@ func (v *Repository) CreateCommit(
var cparents []*C.git_commit = nil
var parentsarg **C.git_commit = nil
- nparents:= len(parents)
+ nparents := len(parents)
if nparents > 0 {
cparents = make([]*C.git_commit, nparents)
for i, v := range parents {
@@ -226,7 +227,7 @@ func (repo *Repository) Path() string {
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
}
@@ -249,6 +250,7 @@ func (v *Repository) TreeBuilder() (*TreeBuilder, error) {
if ret := C.git_treebuilder_create(&bld.ptr, nil); ret < 0 {
return nil, LastError()
}
+ runtime.SetFinalizer(bld, (*TreeBuilder).Free)
bld.repo = v
return bld, nil