Skip to content
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

Use pthread_equal for pthread_t comparison #3022

Merged
merged 1 commit into from
Aug 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions utils/s2n_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ unsigned long s2n_get_openssl_version(void)
}

static pthread_t main_thread = 0;

static bool initialized = false;
static bool atexit_cleanup = true;
int s2n_disable_atexit(void) {
const bool already_initialized = (main_thread != 0);
POSIX_ENSURE(!already_initialized, S2N_ERR_INITIALIZED);
POSIX_ENSURE(!initialized, S2N_ERR_INITIALIZED);
atexit_cleanup = false;
return S2N_SUCCESS;
}
Expand All @@ -69,6 +68,8 @@ int s2n_init(void)
s2n_stack_traces_enabled_set(true);
}

initialized = true;

return S2N_SUCCESS;
}

Expand All @@ -92,7 +93,7 @@ int s2n_cleanup(void)

/* If this is the main thread and atexit cleanup is disabled,
* perform final cleanup now */
if (pthread_self() == main_thread && !atexit_cleanup) {
if (pthread_equal(pthread_self(), main_thread) && !atexit_cleanup) {
POSIX_ENSURE(s2n_cleanup_atexit_impl(), S2N_ERR_ATEXIT);
}
return 0;
Expand Down