@@ -59,6 +59,7 @@ TEST_F(test, disjointCoarseMallocPool_name_upstream) {
5959 sizeof (coarse_memory_provider_params));
6060 coarse_memory_provider_params.upstream_memory_provider =
6161 malloc_memory_provider;
62+ coarse_memory_provider_params.destroy_upstream_memory_provider = true ;
6263 coarse_memory_provider_params.immediate_init_from_upstream = true ;
6364 coarse_memory_provider_params.init_buffer = nullptr ;
6465 coarse_memory_provider_params.init_buffer_size = init_buffer_size;
@@ -75,7 +76,8 @@ TEST_F(test, disjointCoarseMallocPool_name_upstream) {
7576 0 );
7677
7778 umfMemoryProviderDestroy (coarse_memory_provider);
78- umfMemoryProviderDestroy (malloc_memory_provider);
79+ // malloc_memory_provider has been already destroyed, because:
80+ // coarse_memory_provider_params.destroy_upstream_memory_provider = true;
7981}
8082
8183TEST_F (test, disjointCoarseMallocPool_name_no_upstream) {
@@ -760,6 +762,37 @@ TEST_P(CoarseWithMemoryStrategyTest, disjointCoarseMallocPool_wrong_params_4) {
760762 umfMemoryProviderDestroy (malloc_memory_provider);
761763}
762764
765+ // wrong parameters: destroy_upstream_memory_provider is true, but an upstream provider is not provided
766+ TEST_P (CoarseWithMemoryStrategyTest, disjointCoarseMallocPool_wrong_params_5) {
767+ umf_result_t umf_result;
768+
769+ const size_t init_buffer_size = 20 * MB;
770+
771+ // Preallocate some memory
772+ std::unique_ptr<char []> buffer (new char [init_buffer_size]);
773+ void *buf = buffer.get ();
774+ ASSERT_NE (buf, nullptr );
775+ memset (buf, 0 , init_buffer_size);
776+
777+ coarse_memory_provider_params_t coarse_memory_provider_params;
778+ // make sure there are no undefined members - prevent a UB
779+ memset (&coarse_memory_provider_params, 0 ,
780+ sizeof (coarse_memory_provider_params));
781+ coarse_memory_provider_params.allocation_strategy = allocation_strategy;
782+ coarse_memory_provider_params.upstream_memory_provider = nullptr ;
783+ coarse_memory_provider_params.destroy_upstream_memory_provider = true ;
784+ coarse_memory_provider_params.immediate_init_from_upstream = false ;
785+ coarse_memory_provider_params.init_buffer = buf;
786+ coarse_memory_provider_params.init_buffer_size = init_buffer_size;
787+
788+ umf_memory_provider_handle_t coarse_memory_provider = nullptr ;
789+ umf_result = umfMemoryProviderCreate (umfCoarseMemoryProviderOps (),
790+ &coarse_memory_provider_params,
791+ &coarse_memory_provider);
792+ ASSERT_EQ (umf_result, UMF_RESULT_ERROR_INVALID_ARGUMENT);
793+ ASSERT_EQ (coarse_memory_provider, nullptr );
794+ }
795+
763796TEST_P (CoarseWithMemoryStrategyTest, disjointCoarseMallocPool_split_merge) {
764797 umf_memory_provider_handle_t malloc_memory_provider;
765798 umf_result_t umf_result;
0 commit comments