Repository navigation
Conversation
Co-authored-by: alt-graph <28754274+alt-graph@users.noreply.github.com>
|
Modified and cherry-picked into main. |
|
The fix is ok-ish, but maybe it is a bit too narrow minded? It fixes cases when a I find the LLM explanation a bit superficial and the fix incomplete. In the That is all sound and good, BUT we have a lot more objects here libgit4cpp/include/libgit4cpp/types.h Lines 33 to 43 in 02dbfb6 that all can outlive the libgit2 shutdown. The library itself suggests: Usually you don’t need to call the shutdown function
https://libgit2.org/docs/guides/101-samples/ For example one of our wrapper functions: LibGitStatusList status_list_new(
git_repository* repo, const git_status_options& status_opt);We need a So, I would strive for a more general solutionWe could create 'new' deallocator functions, that first call the libgit object-specific free and then shutdown, i.e. decrement the refcounter (and of course all objects need to call libgit2's init to increment the counter first. Which is a hassle, but Imho much more straightforward then this Or we can go by the suggestion of libgit's maintainers and just init() the library whereever needed and never shutdown (which might look a bit 'dirty', but otoh thats also the case with the standard file descriptors and streams etc... The merged solution is ... just an 'LLM fix', and not a good one at that 😒 Edit: For the libgit4cpp user who wants "correct" memory management, we could always just add a function void git::LibGitShutdown() {
while (git_libgit2_shutdown() > 0);
} |

ASAN reports a small leak (3 allocations, 200 bytes) originating in
git_error_setwhen agit::Remoteis destroyed. This is likely caused by theRemoteoutliving itsRepository, not by libgit2 itself.Repositorycallsgit_libgit2_init()/git_libgit2_shutdown()in its constructor and destructor. ARemotecan outlive itsRepository, astest_Remote.ccdoes withrepo.reset(). When that happens,git_remote_freeruns after the final shutdown and sets a fresh thread-local error. Nothing frees that error afterwards.Remote.hLibGitInitGuardmember that takes a libgit2 init reference on construction and releases it on destruction.remote_, so it is destroyed aftergit_remote_freeruns.Remoteis moved.I couldn't build or run the tests in my environment, so the fix is unverified. Please confirm with an ASAN build on Ubuntu 26.04.