diff options
author | shridhar kalavagunta <coolshrid@hotmail.com> | 2024-04-29 20:59:57 -0500 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2024-05-20 10:11:35 +0200 |
commit | 4dbd4925dfc61d93df678df607504f62b0ac3dcc (patch) | |
tree | fd4ccddd5f2268451f981cc8c470f8eb3989092d /test | |
parent | 45f5d51b72a262bf85c4461fbded91485ce6b9da (diff) | |
download | openssl-4dbd4925dfc61d93df678df607504f62b0ac3dcc.zip openssl-4dbd4925dfc61d93df678df607504f62b0ac3dcc.tar.gz openssl-4dbd4925dfc61d93df678df607504f62b0ac3dcc.tar.bz2 |
Fix mem leak in threadpool_test.c
Fixes #24104
Added a goto label for cleanup.
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24412)
Diffstat (limited to 'test')
-rw-r--r-- | test/threadpool_test.c | 78 |
1 files changed, 41 insertions, 37 deletions
diff --git a/test/threadpool_test.c b/test/threadpool_test.c index 90ddaa9..070c7cb 100644 --- a/test/threadpool_test.c +++ b/test/threadpool_test.c @@ -100,6 +100,7 @@ static int test_thread_internal(void) uint32_t threads_supported; size_t i; void *t[3]; + int status = 0; OSSL_LIB_CTX *cust_ctx = OSSL_LIB_CTX_new(); threads_supported = OSSL_get_thread_support_flags(); @@ -107,65 +108,66 @@ static int test_thread_internal(void) if (threads_supported == 0) { if (!TEST_uint64_t_eq(OSSL_get_max_threads(NULL), 0)) - return 0; + goto cleanup; if (!TEST_uint64_t_eq(OSSL_get_max_threads(cust_ctx), 0)) - return 0; + goto cleanup; if (!TEST_int_eq(OSSL_set_max_threads(NULL, 1), 0)) - return 0; + goto cleanup; if (!TEST_int_eq(OSSL_set_max_threads(cust_ctx, 1), 0)) - return 0; + goto cleanup; if (!TEST_uint64_t_eq(OSSL_get_max_threads(NULL), 0)) - return 0; + goto cleanup; if (!TEST_uint64_t_eq(OSSL_get_max_threads(cust_ctx), 0)) - return 0; + goto cleanup; t[0] = ossl_crypto_thread_start(NULL, test_thread_native_fn, &local[0]); if (!TEST_ptr_null(t[0])) - return 0; + goto cleanup; - return 1; + status = 1; + goto cleanup; } /* fail when not allowed to use threads */ if (!TEST_uint64_t_eq(OSSL_get_max_threads(NULL), 0)) - return 0; + goto cleanup; t[0] = ossl_crypto_thread_start(NULL, test_thread_native_fn, &local[0]); if (!TEST_ptr_null(t[0])) - return 0; + goto cleanup; /* fail when enabled on a different context */ if (!TEST_uint64_t_eq(OSSL_get_max_threads(cust_ctx), 0)) - return 0; + goto cleanup; if (!TEST_int_eq(OSSL_set_max_threads(cust_ctx, 1), 1)) - return 0; + goto cleanup; if (!TEST_uint64_t_eq(OSSL_get_max_threads(NULL), 0)) - return 0; + goto cleanup; if (!TEST_uint64_t_eq(OSSL_get_max_threads(cust_ctx), 1)) - return 0; + goto cleanup; t[0] = ossl_crypto_thread_start(NULL, test_thread_native_fn, &local[0]); if (!TEST_ptr_null(t[0])) - return 0; + goto cleanup; if (!TEST_int_eq(OSSL_set_max_threads(cust_ctx, 0), 1)) - return 0; + goto cleanup; /* sequential startup */ if (!TEST_int_eq(OSSL_set_max_threads(NULL, 1), 1)) - return 0; + goto cleanup; if (!TEST_uint64_t_eq(OSSL_get_max_threads(NULL), 1)) - return 0; + goto cleanup; if (!TEST_uint64_t_eq(OSSL_get_max_threads(cust_ctx), 0)) - return 0; + goto cleanup; for (i = 0; i < OSSL_NELEM(t); ++i) { local[0] = i + 1; t[i] = ossl_crypto_thread_start(NULL, test_thread_native_fn, &local[0]); if (!TEST_ptr(t[i])) - return 0; + goto cleanup; /* * pthread_join results in undefined behaviour if called on a joined @@ -174,70 +176,72 @@ static int test_thread_internal(void) * if we do). */ if (!TEST_int_eq(ossl_crypto_thread_join(t[i], &retval[0]), 1)) - return 0; + goto cleanup; if (!TEST_int_eq(ossl_crypto_thread_join(t[i], &retval[0]), 1)) - return 0; + goto cleanup; if (!TEST_int_eq(retval[0], i + 1) || !TEST_int_eq(local[0], i + 2)) - return 0; + goto cleanup; if (!TEST_int_eq(ossl_crypto_thread_clean(t[i]), 1)) - return 0; + goto cleanup; t[i] = NULL; if (!TEST_int_eq(ossl_crypto_thread_clean(t[i]), 0)) - return 0; + goto cleanup; } /* parallel startup */ if (!TEST_int_eq(OSSL_set_max_threads(NULL, OSSL_NELEM(t)), 1)) - return 0; + goto cleanup; for (i = 0; i < OSSL_NELEM(t); ++i) { local[i] = i + 1; t[i] = ossl_crypto_thread_start(NULL, test_thread_native_fn, &local[i]); if (!TEST_ptr(t[i])) - return 0; + goto cleanup; } for (i = 0; i < OSSL_NELEM(t); ++i) { if (!TEST_int_eq(ossl_crypto_thread_join(t[i], &retval[i]), 1)) - return 0; + goto cleanup; } for (i = 0; i < OSSL_NELEM(t); ++i) { if (!TEST_int_eq(retval[i], i + 1) || !TEST_int_eq(local[i], i + 2)) - return 0; + goto cleanup; if (!TEST_int_eq(ossl_crypto_thread_clean(t[i]), 1)) - return 0; + goto cleanup; } /* parallel startup, bottleneck */ if (!TEST_int_eq(OSSL_set_max_threads(NULL, OSSL_NELEM(t) - 1), 1)) - return 0; + goto cleanup; for (i = 0; i < OSSL_NELEM(t); ++i) { local[i] = i + 1; t[i] = ossl_crypto_thread_start(NULL, test_thread_native_fn, &local[i]); if (!TEST_ptr(t[i])) - return 0; + goto cleanup; } for (i = 0; i < OSSL_NELEM(t); ++i) { if (!TEST_int_eq(ossl_crypto_thread_join(t[i], &retval[i]), 1)) - return 0; + goto cleanup; } for (i = 0; i < OSSL_NELEM(t); ++i) { if (!TEST_int_eq(retval[i], i + 1) || !TEST_int_eq(local[i], i + 2)) - return 0; + goto cleanup; if (!TEST_int_eq(ossl_crypto_thread_clean(t[i]), 1)) - return 0; + goto cleanup; } if (!TEST_int_eq(OSSL_set_max_threads(NULL, 0), 1)) - return 0; + goto cleanup; + status = 1; +cleanup: OSSL_LIB_CTX_free(cust_ctx); - return 1; + return status; } # endif |