memory leak in tree method "EntryByPath" #313
Labels
No Label
bug
duplicate
enhancement
invalid
question
up for grabs
wontfix
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: jcarr/git2go#313
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
We have found memory leak in our project when calling EntryByPath method. After reading source code of git2go and libgit2, C.git_tree_entry_bypath allocates memory but not free in this method. I think that's the root cause for memory leak.
By calling "defer C.git_tree_entry_free(entry)" before return is a solution for this problem. So What do you think? @carlosmn
Indeed, this leaks the
git_tree_entry
and we should be freeing it after creating the Go structure.@carlosmn The Go structure is created by function newTreeEntry. Do you mean to free git_tree_entry at the end of that function?
There are some methods have called function newTreeEntry but only EntryByPath allocates extra memory because it used C.git_tree_entry_bypath . Other methods such as EntryById and EntryByName do not allocate C side memory. So we should not free their git_tree_entry.
So I think the appropriate solution is using C.git_tree_entry_free after called newTreeEntry and before EntryByPath returned, just like:
Yes, the caller owns the entry, as we cannot statically know whether the entry will be in the tree given as input. That code would work, though the defer seems overkill when we could have a local variable.