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

feat: Adds cleanup_final #4853

Merged
merged 6 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 11 additions & 0 deletions api/s2n.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,17 @@ S2N_API extern int s2n_init(void);
*/
S2N_API extern int s2n_cleanup(void);

/*
* Performs a complete deinitialization and cleanup of the s2n-tls library.
*
* The difference between this API and s2n_cleanup is that s2n_cleanup will not fully clean up the library
* if the atexit handler is enabled or it is called on a thread that did not call s2n_init. s2n_cleanup_final
* will always fully deinitialize the library.
*
* @returns S2N_SUCCESS on success. S2N_FAILURE on failure
*/
S2N_API extern int s2n_cleanup_final(void);

typedef enum {
S2N_FIPS_MODE_DISABLED = 0,
S2N_FIPS_MODE_ENABLED,
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/s2n_init_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ int main(int argc, char **argv)
EXPECT_FAILURE_WITH_ERRNO(s2n_cleanup(), S2N_ERR_NOT_INITIALIZED);
}

/* Calling s2n_cleanup_final will de-initialize the library */
{
EXPECT_SUCCESS(s2n_init());
EXPECT_TRUE(s2n_is_initialized());
EXPECT_SUCCESS(s2n_cleanup_final());
EXPECT_FALSE(s2n_is_initialized());
}

/* The following test requires atexit to be enabled. */
EXPECT_SUCCESS(s2n_enable_atexit());

Expand Down
Loading