@@ -88,6 +88,7 @@ func (repo *Repository) NewBranchIterator(flags BranchType) (*BranchIterator, er
8888 defer runtime .UnlockOSThread ()
8989
9090 ecode := C .git_branch_iterator_new (& ptr , repo .ptr , refType )
91+ runtime .KeepAlive (repo )
9192 if ecode < 0 {
9293 return nil , MakeGitError (ecode )
9394 }
@@ -106,6 +107,8 @@ func (repo *Repository) CreateBranch(branchName string, target *Commit, force bo
106107 defer runtime .UnlockOSThread ()
107108
108109 ret := C .git_branch_create (& ptr , repo .ptr , cBranchName , target .cast_ptr , cForce )
110+ runtime .KeepAlive (repo )
111+ runtime .KeepAlive (target )
109112 if ret < 0 {
110113 return nil , MakeGitError (ret )
111114 }
@@ -117,6 +120,7 @@ func (b *Branch) Delete() error {
117120 runtime .LockOSThread ()
118121 defer runtime .UnlockOSThread ()
119122 ret := C .git_branch_delete (b .Reference .ptr )
123+ runtime .KeepAlive (b .Reference )
120124 if ret < 0 {
121125 return MakeGitError (ret )
122126 }
@@ -133,6 +137,7 @@ func (b *Branch) Move(newBranchName string, force bool) (*Branch, error) {
133137 defer runtime .UnlockOSThread ()
134138
135139 ret := C .git_branch_move (& ptr , b .Reference .ptr , cNewBranchName , cForce )
140+ runtime .KeepAlive (b .Reference )
136141 if ret < 0 {
137142 return nil , MakeGitError (ret )
138143 }
@@ -145,6 +150,7 @@ func (b *Branch) IsHead() (bool, error) {
145150 defer runtime .UnlockOSThread ()
146151
147152 ret := C .git_branch_is_head (b .Reference .ptr )
153+ runtime .KeepAlive (b .Reference )
148154 switch ret {
149155 case 1 :
150156 return true , nil
@@ -165,6 +171,7 @@ func (repo *Repository) LookupBranch(branchName string, bt BranchType) (*Branch,
165171 defer runtime .UnlockOSThread ()
166172
167173 ret := C .git_branch_lookup (& ptr , repo .ptr , cName , C .git_branch_t (bt ))
174+ runtime .KeepAlive (repo )
168175 if ret < 0 {
169176 return nil , MakeGitError (ret )
170177 }
@@ -179,6 +186,7 @@ func (b *Branch) Name() (string, error) {
179186 defer runtime .UnlockOSThread ()
180187
181188 ret := C .git_branch_name (& cName , b .Reference .ptr )
189+ runtime .KeepAlive (b .Reference )
182190 if ret < 0 {
183191 return "" , MakeGitError (ret )
184192 }
@@ -196,6 +204,7 @@ func (repo *Repository) RemoteName(canonicalBranchName string) (string, error) {
196204 defer runtime .UnlockOSThread ()
197205
198206 ret := C .git_branch_remote_name (& nameBuf , repo .ptr , cName )
207+ runtime .KeepAlive (repo )
199208 if ret < 0 {
200209 return "" , MakeGitError (ret )
201210 }
@@ -212,6 +221,7 @@ func (b *Branch) SetUpstream(upstreamName string) error {
212221 defer runtime .UnlockOSThread ()
213222
214223 ret := C .git_branch_set_upstream (b .Reference .ptr , cName )
224+ runtime .KeepAlive (b .Reference )
215225 if ret < 0 {
216226 return MakeGitError (ret )
217227 }
@@ -225,6 +235,7 @@ func (b *Branch) Upstream() (*Reference, error) {
225235 defer runtime .UnlockOSThread ()
226236
227237 ret := C .git_branch_upstream (& ptr , b .Reference .ptr )
238+ runtime .KeepAlive (b .Reference )
228239 if ret < 0 {
229240 return nil , MakeGitError (ret )
230241 }
@@ -241,6 +252,7 @@ func (repo *Repository) UpstreamName(canonicalBranchName string) (string, error)
241252 defer runtime .UnlockOSThread ()
242253
243254 ret := C .git_branch_upstream_name (& nameBuf , repo .ptr , cName )
255+ runtime .KeepAlive (repo )
244256 if ret < 0 {
245257 return "" , MakeGitError (ret )
246258 }
0 commit comments