Skip to content

Segfault on uninitialized git global allocator #491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dtolnay opened this issue Nov 16, 2019 · 2 comments · Fixed by #494
Closed

Segfault on uninitialized git global allocator #491

dtolnay opened this issue Nov 16, 2019 · 2 comments · Fixed by #494

Comments

@dtolnay
Copy link
Member

dtolnay commented Nov 16, 2019

The following code causes a segfault in patch_generated_with_delta_alloc.

fn main() {
    git2::Patch::from_buffers(
        "abc".as_bytes(),
        None,
        "abc".as_bytes(),
        None,
        None,
    );
}

I believe this is because git's global allocator never gets initialized. A workaround is to add libgit2_sys::init() at the top of main. Should this be necessary, or should the safe git2 binding be calling init in more places?

@ehuss
Copy link
Contributor

ehuss commented Nov 17, 2019

I think generally the safe git2 side usually calls init from every function that needs it. The way libgit2 handles allocation was changed recently, so now a significantly larger portion of the API should be calling init.

I wonder if there should be any concern about the performance impact of calling init everywhere.

alexcrichton added a commit to alexcrichton/git2-rs that referenced this issue Nov 18, 2019
@alexcrichton
Copy link
Member

Yes git2 should always handle initialization. I don't think it'll be much of a performance issue but we can always handle it if it does.

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 a pull request may close this issue.

3 participants