| 1 | /* |
| 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | * You may not use this file except in compliance with the License. |
| 6 | * A copy of the License is located at |
| 7 | * |
| 8 | * http://aws.amazon.com/apache2.0 |
| 9 | * |
| 10 | * or in the "license" file accompanying this file. This file is distributed |
| 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | * express or implied. See the License for the specific language governing |
| 13 | * permissions and limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #include <pthread.h> |
| 17 | |
| 18 | #include "s2n_test.h" |
| 19 | |
| 20 | static int my_global; |
| 21 | |
| 22 | static void my_destructor(void *arg) {} |
| 23 | |
| 24 | /* Checks that calling s2n_cleanup without s2n_init does not corrupt |
| 25 | * thread-local storage. */ |
| 26 | |
| 27 | int main(int argc, char **argv) |
| 28 | { |
| 29 | BEGIN_TEST_NO_INIT(); |
| 30 | |
| 31 | pthread_key_t my_key = 0; |
| 32 | |
| 33 | /* Init the pthread key */ |
| 34 | EXPECT_SUCCESS(pthread_key_create(&my_key, my_destructor)); |
| 35 | |
| 36 | /* Set it a value */ |
| 37 | EXPECT_SUCCESS(pthread_setspecific(my_key, &my_global)); |
| 38 | |
| 39 | /* Call s2n_cleanup with no init */ |
| 40 | EXPECT_SUCCESS(s2n_cleanup()); |
| 41 | |
| 42 | /* Check that the key is not corrupted */ |
| 43 | int *new_value = (int *) pthread_getspecific(my_key); |
| 44 | EXPECT_EQUAL(new_value, &my_global); |
| 45 | |
| 46 | /* Delete the key */ |
| 47 | EXPECT_SUCCESS(pthread_key_delete(my_key)); |
| 48 | |
| 49 | END_TEST_NO_INIT(); |
| 50 | } |