Convert diff contents to CBuffer and free it instead of using a CString

This commit is contained in:
Michael Boulton 2020-08-17 08:15:14 +01:00
parent 2edef4dbea
commit d8f155f971
No known key found for this signature in database
GPG Key ID: 8A62CA0BE2E0197E
1 changed files with 4 additions and 1 deletions

View File

@ -969,10 +969,13 @@ func (v *Repository) ApplyDiff(diff *Diff, location GitApplyLocation, opts *Appl
func DiffFromBuffer(buffer []byte, repo *Repository) (*Diff, error) {
var diff *C.git_diff
cBuffer := C.CBytes(buffer)
defer C.free(unsafe.Pointer(cBuffer))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ecode := C.git_diff_from_buffer(&diff, C.CString(string(buffer)), C.size_t(len(buffer)))
ecode := C.git_diff_from_buffer(&diff, (*C.char)(cBuffer), C.size_t(len(buffer)))
if ecode < 0 {
return nil, MakeGitError(ecode)
}