Skip to content

Errors can happen during init, before git__n_inits is initialized, which leads to a failed assertion #3318

@joshaber

Description

@joshaber
  1. git__getenv: utf-8 aware env reader #3288 introduced git__getenv, which introduced a bit more error handling in environment lookup than we had before.
  2. In POSIX, git_libgit2_init calls init_once before incrementing git__n_inits. (
    pthread_once(&_once_init, init_once);
    )
  3. init_once calls various other init functions: https://github.com/libgit2/libgit2/blob/42156d561723e92ffe597885719aa63abfe0795c/src/global.c#L334-338
  4. Some of those global init functions (namely git_sysdir_global_init) can error (
    if (error == GIT_ENOTFOUND) {
    ), which means we try to clear the last_error.
  5. Setting the last_error accesses git__global_state (
    if (GIT_GLOBAL->last_error != NULL) {
    ).
  6. git__global_state asserts that git__n_inits > 0 (
    assert(git_atomic_get(&git__n_inits) > 0);
    )
  7. 💥 We fail the assertion.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions