Skip to content

Commit

Permalink
Use pthread_equal for pthread_t comparison (#3022)
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Boswell authored Aug 25, 2021
1 parent c19ad51 commit b5b313b
Showing 1 changed file with 5 additions and 4 deletions.
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

0 comments on commit b5b313b

Please sign in to comment.