Fix memory leak in Patch.String()
Buffer allocated in Patch.String() was never freed Signed-off-by: Can Berk Güder <cbguder@pivotal.io>
This commit is contained in:
parent
4a14260153
commit
de521bb2b4
5
patch.go
5
patch.go
|
@ -40,15 +40,18 @@ func (patch *Patch) String() (string, error) {
|
||||||
if patch.ptr == nil {
|
if patch.ptr == nil {
|
||||||
return "", ErrInvalid
|
return "", ErrInvalid
|
||||||
}
|
}
|
||||||
var buf C.git_buf
|
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
var buf C.git_buf
|
||||||
|
|
||||||
ecode := C.git_patch_to_buf(&buf, patch.ptr)
|
ecode := C.git_patch_to_buf(&buf, patch.ptr)
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return "", MakeGitError(ecode)
|
return "", MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
|
defer C.git_buf_free(&buf)
|
||||||
|
|
||||||
return C.GoString(buf.ptr), nil
|
return C.GoString(buf.ptr), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue