Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

implausible
Copy link
Member

We don't have a very good pattern for garbage collection in callback parameters at the moment. After introducing garbage collection elsewhere in the library, we left callback parameters as not garbage collected, because they typically are owned by libgit2 anyway. So as long libgit2 is cleaning up their pointer, and we're cleaning up our v8 object, the memory ends up being cleaned up anyway.

The caveat was that callback parameters should not be trusted after a callback exits.

What sucks is that we discovered that you can access a git_repository from a git_filter_source, and that the git_repository that you can access is not guaranteed to be a git_repository that nodegit has ever seen before. In fact, it may not even be owned by NodeGit. In the case of submodules, when a git_submodule_status is performed, the filters are invoked with a repository that is internal to git_submodule_status. This means that those repos are freed by libgit2, and are never owned by nodegit.

This PR addresses that segfault, by making the git_filter_source repo getter async, and having that getter open a new repo that nodegit owns. This PR also removes access to git_diff in git_diff_notify_cb and git_diff_progress_cb, as I can't figure out a good way to handle that memory access at the moment... Something something tree invalidation 😅.

This is especially helpful right now, because certain parameters have difficult garbage collection patterns. At the very least, for cases where a garbage collection pattern has not been fully fleshed out, we can ignore certain callback parameters until we can safely handle their memory.
We discovered that after the garbage collection PR, that submodules can trigger the filter with a filter_source that has a repo that NodeGit has never seen before. This causes libgit2 to free their repo, and us to free what we thought was our repo. As a temporary stopgap to allow filter writers to user repos, I've converted the repo getter to async, and opened a nodegit owned repo. This should prevent any segfaults when pulling the repo out during a filter operation at a small perf penalty.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant