Skip to content

Commit 4ee13db

Browse files
committed
Merge pull request libgit2#271 from joseferminj/fix-memory-problems
Fix Fetch/Push memory allocation problems
2 parents f05a6a3 + 92d736d commit 4ee13db

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

remote.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -623,14 +623,16 @@ func (o *Remote) Fetch(refspecs []string, opts *FetchOptions, msg string) error
623623
crefspecs.strings = makeCStringsFromStrings(refspecs)
624624
defer freeStrarray(&crefspecs)
625625

626-
var coptions C.git_fetch_options
627-
populateFetchOptions(&coptions, opts);
626+
coptions := (*C.git_fetch_options)(C.calloc(1, C.size_t(unsafe.Sizeof(C.git_fetch_options{}))))
627+
defer C.free(unsafe.Pointer(coptions))
628+
629+
populateFetchOptions(coptions, opts)
628630
defer untrackCalbacksPayload(&coptions.callbacks)
629631

630632
runtime.LockOSThread()
631633
defer runtime.UnlockOSThread()
632634

633-
ret := C.git_remote_fetch(o.ptr, &crefspecs, &coptions, cmsg)
635+
ret := C.git_remote_fetch(o.ptr, &crefspecs, coptions, cmsg)
634636
if ret < 0 {
635637
return MakeGitError(ret)
636638
}
@@ -710,14 +712,16 @@ func (o *Remote) Push(refspecs []string, opts *PushOptions) error {
710712
crefspecs.strings = makeCStringsFromStrings(refspecs)
711713
defer freeStrarray(&crefspecs)
712714

713-
var coptions C.git_push_options
714-
populatePushOptions(&coptions, opts)
715+
coptions := (*C.git_push_options)(C.calloc(1, C.size_t(unsafe.Sizeof(C.git_push_options{}))))
716+
defer C.free(unsafe.Pointer(coptions))
717+
718+
populatePushOptions(coptions, opts)
715719
defer untrackCalbacksPayload(&coptions.callbacks)
716720

717721
runtime.LockOSThread()
718722
defer runtime.UnlockOSThread()
719723

720-
ret := C.git_remote_push(o.ptr, &crefspecs, &coptions)
724+
ret := C.git_remote_push(o.ptr, &crefspecs, coptions)
721725
if ret < 0 {
722726
return MakeGitError(ret)
723727
}

0 commit comments

Comments
 (0)