libgit2 / objective-git

Objective-C bindings to libgit2
MIT License
1.16k stars 280 forks source link

GTRepository dealloc crash #689

Open arguiot opened 5 years ago

arguiot commented 5 years ago

When the system calls -[GTRepository dealloc] and the git_repository is empty, but still exists, the app crashes.

Here is a screenshot of the debug session:

Capture d’écran 2019-05-16 à 20 27 09

What I would suggest is to change: https://github.com/libgit2/objective-git/blob/b3af3f3c7a1871ba5c153f601f9a643483a665c9/ObjectiveGit/GTRepository.m#L110-L115

By simply checking if the workdir property of the git_repository object isn't empty before cleaning the repo.

I'm not an Objective-C developer, so I let you guys do that for me (or just show me how to do it, and I'll submit a PR)

arguiot commented 5 years ago

Actually, I sent a PR: #690

tiennou commented 5 years ago

Hmm, we're not supposed to care about the repository having a workdir, and I think that your proposed fix leaks the git_repository memory on bare repositories (ie. whenever workdir would have been NULL).

How you've constructed the GTRepository/git_repository itself would be most helpful, right now this could also just be a stray memory write corrupting something in the git_repository. If it's openen from a worktree (a.k.a git worktree list), or a worktree on a bare repo, would also help, as there had been a few issues in libgit2 itself.

arguiot commented 5 years ago

I’m using an Opaque Pointer to create my GTRepository. I will try with a URL, to see if anything changes

tiennou commented 5 years ago

Is that specific to a given repository, or does it happen on any of them ? Could you whip up a test case maybe ?

I don't understand what you mean by Opaque Pointer, and there are a few different ways to get to a GTRepository, some which might not be well-supported (usinggit_repository_new() is the one I'd be surprised would work, or some edge-cases of git_submodule_open). The others should be okay. I just want to clarify if you're only going through Objective-C or if you're somehow customizing something.

arguiot commented 5 years ago

The OpaquePointer I’m talking about is created by SwiftGit2, a small git library for Swift. My project is written in Swift, but I’m able to use Objective Git, as Swift runs on the ObjC runtime.