Skip to content

Commit 490e8a8

Browse files
authored
Merge pull request #368 from cbguder/master
Fix memory leak in Patch.String()
2 parents 89fc9e7 + de521bb commit 490e8a8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

patch.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,18 @@ func (patch *Patch) String() (string, error) {
4040
if patch.ptr == nil {
4141
return "", ErrInvalid
4242
}
43-
var buf C.git_buf
4443

4544
runtime.LockOSThread()
4645
defer runtime.UnlockOSThread()
4746

47+
var buf C.git_buf
48+
4849
ecode := C.git_patch_to_buf(&buf, patch.ptr)
4950
if ecode < 0 {
5051
return "", MakeGitError(ecode)
5152
}
53+
defer C.git_buf_free(&buf)
54+
5255
return C.GoString(buf.ptr), nil
5356
}
5457

0 commit comments

Comments
 (0)