Skip to content

Commit cce14aa

Browse files
committed
branch: fix memory leaks related to CStrings
1 parent ed62fda commit cce14aa

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

branch.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func (repo *Repository) CreateBranch(branchName string, target *Commit, force bo
9494

9595
var ptr *C.git_reference
9696
cBranchName := C.CString(branchName)
97+
defer C.free(unsafe.Pointer(cBranchName))
9798
cForce := cbool(force)
9899

99100
cSignature, err := signature.toC()
@@ -134,6 +135,7 @@ func (b *Branch) Delete() error {
134135
func (b *Branch) Move(newBranchName string, force bool, signature *Signature, msg string) (*Branch, error) {
135136
var ptr *C.git_reference
136137
cNewBranchName := C.CString(newBranchName)
138+
defer C.free(unsafe.Pointer(cNewBranchName))
137139
cForce := cbool(force)
138140

139141
cSignature, err := signature.toC()
@@ -180,6 +182,7 @@ func (repo *Repository) LookupBranch(branchName string, bt BranchType) (*Branch,
180182
var ptr *C.git_reference
181183

182184
cName := C.CString(branchName)
185+
defer C.free(unsafe.Pointer(cName))
183186

184187
runtime.LockOSThread()
185188
defer runtime.UnlockOSThread()
@@ -208,6 +211,7 @@ func (b *Branch) Name() (string, error) {
208211

209212
func (repo *Repository) RemoteName(canonicalBranchName string) (string, error) {
210213
cName := C.CString(canonicalBranchName)
214+
defer C.free(unsafe.Pointer(cName))
211215

212216
nameBuf := C.git_buf{}
213217

@@ -225,6 +229,7 @@ func (repo *Repository) RemoteName(canonicalBranchName string) (string, error) {
225229

226230
func (b *Branch) SetUpstream(upstreamName string) error {
227231
cName := C.CString(upstreamName)
232+
defer C.free(unsafe.Pointer(cName))
228233

229234
runtime.LockOSThread()
230235
defer runtime.UnlockOSThread()
@@ -251,6 +256,7 @@ func (b *Branch) Upstream() (*Reference, error) {
251256

252257
func (repo *Repository) UpstreamName(canonicalBranchName string) (string, error) {
253258
cName := C.CString(canonicalBranchName)
259+
defer C.free(unsafe.Pointer(cName))
254260

255261
nameBuf := C.git_buf{}
256262

0 commit comments

Comments
 (0)