runtime: prevent refcount underflow on extra shutdown calls by qaqland · Pull Request #7299 · libgit2/libgit2 · GitHub
Skip to content

runtime: prevent refcount underflow on extra shutdown calls#7299

Open
qaqland wants to merge 1 commit into
libgit2:mainfrom
qaqland:extra-shutdown
Open

runtime: prevent refcount underflow on extra shutdown calls#7299
qaqland wants to merge 1 commit into
libgit2:mainfrom
qaqland:extra-shutdown

Conversation

@qaqland

@qaqland qaqland commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Signed-off-by: qaqland <anguoli@uniontech.com>
@ethomson

Copy link
Copy Markdown
Member

@qaqland

qaqland commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the quick reply. I found this while checking whether cleanup/shutdown functions can be called idly, much like the free(NULL).

The concrete issue is the API contract. As the documentation says, git_libgit2_shutdown() returns the number of remaining init count or an error code. Underflow produces a negative value that is neither, violating the documented semantics.

it also feels like we have a test and set race.

I don't think there's a race, both the get and dec are inside the lock.

Should we just check for <= 0 on the decrement instead?

In this case, the counter has already gone negative. That would also require git_libgit2_init() to be changed.

@c14n

c14n commented Jun 25, 2026

Copy link
Copy Markdown

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.

3 participants