Skip to content

Refactor ConfigEntry and related iterators for safer memory management - #1499

Open
beamerblvd wants to merge 1 commit into
libgit2:masterfrom
beamerblvd:fix-configentry-memory-safety
Open

beamerblvd wants to merge 1 commit into
libgit2:masterfrom
beamerblvd:fix-configentry-memory-safety

Conversation

@beamerblvd

Copy link
Copy Markdown
Contributor

ConfigEntry is holding on to git_config_entry pointers for its entire lifespan, but this isn't safe or necessary. When getting a single entry without an iterator, this isn't really a concern. However, when entries are iterated with git_config_next, the previously-allocated iterator entry object is re-used. If ConfigEntry is still holding onto the git_config_entry, its values could change inappropriately and unexpectedly. The solution to this is to eagerly copy the underlying C values into the Python structure and move on.

Additionally, git_config_entry_free should never be used for iterated entries. Freeing the iterator automatically frees any entries it allocated, and manually freeing the entry can cause a crash. git_config_entry_free should be called only for entries retrieved without an iterator.

This pull request, which is a subset of the changes initially proposed in #1473, fixes this memory misuse by refactoring ConfigEntry and its related iterators.

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