Index memory leaks? #267

Closed
opened 2015-10-27 03:06:58 -05:00 by ryot4 · 1 comment
ryot4 commented 2015-10-27 03:06:58 -05:00 (Migrated from github.com)

Index has Free() method and newIndexFromC() makes sure the method is called.
newIndexFromC() is used in Repository.Index(), but not in NewIndex() and OpenIndex().

I think this causes memory leaks when we use these functions without calling Index.Free() explicitly.

`Index` has [`Free()`](https://github.com/libgit2/git2go/blob/3b5633de219eec2908723a8e557758cc055d84d1/index.go#L317-L320) method and [`newIndexFromC()`](https://github.com/libgit2/git2go/blob/3b5633de219eec2908723a8e557758cc055d84d1/index.go#L82-L86) makes sure the method is called. `newIndexFromC()` is used in [`Repository.Index()`](https://github.com/libgit2/git2go/blob/3b5633de219eec2908723a8e557758cc055d84d1/repository.go#L145), but not in [`NewIndex()`](https://github.com/libgit2/git2go/blob/3b5633de219eec2908723a8e557758cc055d84d1/index.go#L90-L101) and [`OpenIndex()`](https://github.com/libgit2/git2go/blob/3b5633de219eec2908723a8e557758cc055d84d1/index.go#L105-L119). I think this causes memory leaks when we use these functions without calling `Index.Free()` explicitly.
carlosmn commented 2015-10-29 06:15:08 -05:00 (Migrated from github.com)

Yes, that is correct. Those uses do not set the finalizer to free the C memory. It's likely a result of newIndexFromC() not existing when those were created.

Yes, that is correct. Those uses do not set the finalizer to free the C memory. It's likely a result of `newIndexFromC()` not existing when those were created.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: jcarr/git2go#267
No description provided.