@@ -59,6 +59,7 @@ TEST_F(test, disjointCoarseMallocPool_name_upstream) {
59
59
sizeof (coarse_memory_provider_params));
60
60
coarse_memory_provider_params.upstream_memory_provider =
61
61
malloc_memory_provider;
62
+ coarse_memory_provider_params.destroy_upstream_memory_provider = true ;
62
63
coarse_memory_provider_params.immediate_init_from_upstream = true ;
63
64
coarse_memory_provider_params.init_buffer = nullptr ;
64
65
coarse_memory_provider_params.init_buffer_size = init_buffer_size;
@@ -75,7 +76,8 @@ TEST_F(test, disjointCoarseMallocPool_name_upstream) {
75
76
0 );
76
77
77
78
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;
79
81
}
80
82
81
83
TEST_F (test, disjointCoarseMallocPool_name_no_upstream) {
@@ -760,6 +762,37 @@ TEST_P(CoarseWithMemoryStrategyTest, disjointCoarseMallocPool_wrong_params_4) {
760
762
umfMemoryProviderDestroy (malloc_memory_provider);
761
763
}
762
764
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
+
763
796
TEST_P (CoarseWithMemoryStrategyTest, disjointCoarseMallocPool_split_merge) {
764
797
umf_memory_provider_handle_t malloc_memory_provider;
765
798
umf_result_t umf_result;
0 commit comments