@@ -191,7 +191,9 @@ TEST_F(shared_heap_test, test_preallocated_shared_heap_malloc_fail)
191191 SharedHeapInitArgs args = {};
192192 WASMSharedHeap *shared_heap = nullptr ;
193193 uint32 argv[1 ] = {}, BUF_SIZE = os_getpagesize ();
194- uint8 preallocated_buf[BUF_SIZE];
194+ uint8 *preallocated_buf = nullptr ;
195+
196+ preallocated_buf = (uint8 *)malloc (BUF_SIZE);
195197
196198 /* create a preallocated shared heap */
197199 args.pre_allocated_addr = preallocated_buf;
@@ -215,6 +217,8 @@ TEST_F(shared_heap_test, test_preallocated_shared_heap_malloc_fail)
215217 test_shared_heap (shared_heap, " test_chain.aot" , " my_shared_heap_malloc" , 1 ,
216218 argv);
217219 EXPECT_EQ (0 , argv[0 ]);
220+
221+ free (preallocated_buf);
218222}
219223
220224TEST_F (shared_heap_test, test_preallocated_shared_runtime_api)
@@ -325,9 +329,12 @@ TEST_F(shared_heap_test, test_shared_heap_rmw)
325329{
326330 WASMSharedHeap *shared_heap = nullptr ;
327331 uint32 argv[2 ] = {}, BUF_SIZE = os_getpagesize ();
328- uint8 preallocated_buf[BUF_SIZE] = {} ;
332+ uint8 * preallocated_buf = nullptr ;
329333 uint32 start1, end1;
330334
335+ preallocated_buf = (uint8_t *)malloc (BUF_SIZE);
336+ ASSERT_NE (preallocated_buf, nullptr );
337+
331338 create_test_shared_heap (preallocated_buf, BUF_SIZE, &shared_heap);
332339
333340 /* app addr for shared heap */
@@ -357,16 +364,25 @@ TEST_F(shared_heap_test, test_shared_heap_rmw)
357364 test_shared_heap (shared_heap, " test.aot" , " read_modify_write_8" , 2 , argv);
358365 EXPECT_EQ (37 , argv[0 ]);
359366 EXPECT_EQ (preallocated_buf[0 ], 98 );
367+
368+ free (preallocated_buf);
360369}
361370
362371TEST_F (shared_heap_test, test_shared_heap_chain_rmw)
363372{
364373 SharedHeapInitArgs args = {};
365374 WASMSharedHeap *shared_heap_chain = nullptr ;
366375 uint32 argv[2 ] = {}, BUF_SIZE = os_getpagesize ();
367- uint8 preallocated_buf[BUF_SIZE] = {}, preallocated_buf2[BUF_SIZE] = {};
376+ uint8 *preallocated_buf = nullptr ;
377+ uint8 *preallocated_buf2 = nullptr ;
368378 uint32 start1, end1, start2, end2;
369379
380+ preallocated_buf = (uint8_t *)malloc (BUF_SIZE);
381+ ASSERT_NE (preallocated_buf, nullptr );
382+
383+ preallocated_buf2 = (uint8_t *)malloc (BUF_SIZE);
384+ ASSERT_NE (preallocated_buf2, nullptr );
385+
370386 create_test_shared_heap_chain (preallocated_buf, BUF_SIZE, preallocated_buf2,
371387 BUF_SIZE, &shared_heap_chain);
372388
@@ -405,16 +421,26 @@ TEST_F(shared_heap_test, test_shared_heap_chain_rmw)
405421 2 , argv);
406422 EXPECT_EQ (0 , argv[0 ]);
407423 EXPECT_EQ (preallocated_buf2[BUF_SIZE - 1 ], 81 );
424+
425+ free (preallocated_buf);
426+ free (preallocated_buf2);
408427}
409428
410429TEST_F (shared_heap_test, test_shared_heap_chain_rmw_bulk_memory)
411430{
412431 SharedHeapInitArgs args = {};
413432 WASMSharedHeap *shared_heap_chain = nullptr ;
414433 uint32 argv[3 ] = {}, BUF_SIZE = os_getpagesize ();
415- uint8 preallocated_buf[BUF_SIZE] = {}, preallocated_buf2[BUF_SIZE] = {};
434+ uint8 *preallocated_buf = nullptr ;
435+ uint8 *preallocated_buf2 = nullptr ;
416436 uint32 start1, end1, start2, end2;
417437
438+ preallocated_buf = (uint8_t *)malloc (BUF_SIZE);
439+ ASSERT_NE (preallocated_buf, nullptr );
440+
441+ preallocated_buf2 = (uint8_t *)malloc (BUF_SIZE);
442+ ASSERT_NE (preallocated_buf2, nullptr );
443+
418444 create_test_shared_heap_chain (preallocated_buf, BUF_SIZE, preallocated_buf2,
419445 BUF_SIZE, &shared_heap_chain);
420446
@@ -460,16 +486,26 @@ TEST_F(shared_heap_test, test_shared_heap_chain_rmw_bulk_memory)
460486 /* no modification since no return value */
461487 EXPECT_EQ (end2, argv[0 ]);
462488 EXPECT_EQ (preallocated_buf2[BUF_SIZE - 1 ], 98 );
489+
490+ free (preallocated_buf);
491+ free (preallocated_buf2);
463492}
464493
465494TEST_F (shared_heap_test, test_shared_heap_chain_rmw_bulk_memory_oob)
466495{
467496 SharedHeapInitArgs args = {};
468497 WASMSharedHeap *shared_heap_chain = nullptr ;
469498 uint32 argv[3 ] = {}, BUF_SIZE = os_getpagesize ();
470- uint8 preallocated_buf[BUF_SIZE] = {}, preallocated_buf2[BUF_SIZE] = {};
499+ uint8 *preallocated_buf = nullptr ;
500+ uint8 *preallocated_buf2 = nullptr ;
471501 uint32 start1, end1, start2, end2;
472502
503+ preallocated_buf = (uint8_t *)malloc (BUF_SIZE);
504+ ASSERT_NE (preallocated_buf, nullptr );
505+
506+ preallocated_buf2 = (uint8_t *)malloc (BUF_SIZE);
507+ ASSERT_NE (preallocated_buf2, nullptr );
508+
473509 create_test_shared_heap_chain (preallocated_buf, BUF_SIZE, preallocated_buf2,
474510 BUF_SIZE, &shared_heap_chain);
475511
@@ -549,9 +585,16 @@ TEST_F(shared_heap_test, test_shared_heap_rmw_oob)
549585{
550586 WASMSharedHeap *shared_heap = nullptr ;
551587 uint32 argv[2 ] = {}, BUF_SIZE = os_getpagesize ();
552- uint8 preallocated_buf[BUF_SIZE], preallocated_buf2[BUF_SIZE];
588+ uint8 *preallocated_buf = nullptr ;
589+ uint8 *preallocated_buf2 = nullptr ;
553590 uint32 start1, end1, start2, end2;
554591
592+ preallocated_buf = (uint8_t *)malloc (BUF_SIZE);
593+ ASSERT_NE (preallocated_buf, nullptr );
594+
595+ preallocated_buf2 = (uint8_t *)malloc (BUF_SIZE);
596+ ASSERT_NE (preallocated_buf2, nullptr );
597+
555598 create_test_shared_heap (preallocated_buf, BUF_SIZE, &shared_heap);
556599
557600 /* app addr for shared heap */
@@ -577,15 +620,25 @@ TEST_F(shared_heap_test, test_shared_heap_rmw_oob)
577620 EXPECT_NONFATAL_FAILURE (test_shared_heap (shared_heap, " test.aot" ,
578621 " read_modify_write_16" , 2 , argv),
579622 " Exception: out of bounds memory access" );
623+
624+ free (preallocated_buf);
625+ free (preallocated_buf2);
580626}
581627
582628TEST_F (shared_heap_test, test_shared_heap_chain_rmw_oob)
583629{
584630 WASMSharedHeap *shared_heap_chain = nullptr ;
585631 uint32 argv[2 ] = {}, BUF_SIZE = os_getpagesize ();
586- uint8 preallocated_buf[BUF_SIZE], preallocated_buf2[BUF_SIZE];
632+ uint8 *preallocated_buf = nullptr ;
633+ uint8 *preallocated_buf2 = nullptr ;
587634 uint32 start1, end1, start2, end2;
588635
636+ preallocated_buf = (uint8_t *)malloc (BUF_SIZE);
637+ ASSERT_NE (preallocated_buf, nullptr );
638+
639+ preallocated_buf2 = (uint8_t *)malloc (BUF_SIZE);
640+ ASSERT_NE (preallocated_buf2, nullptr );
641+
589642 create_test_shared_heap_chain (preallocated_buf, BUF_SIZE, preallocated_buf2,
590643 BUF_SIZE, &shared_heap_chain);
591644
@@ -609,16 +662,25 @@ TEST_F(shared_heap_test, test_shared_heap_chain_rmw_oob)
609662 " test_chain.aot" ,
610663 " read_modify_write_16" , 2 , argv),
611664 " Exception: out of bounds memory access" );
665+ free (preallocated_buf);
666+ free (preallocated_buf2);
612667}
613668
614669#if WASM_ENABLE_MEMORY64 != 0
615670TEST_F (shared_heap_test, test_shared_heap_chain_memory64_rmw)
616671{
617672 WASMSharedHeap *shared_heap_chain = nullptr ;
618673 uint32 argv[3 ] = {}, BUF_SIZE = os_getpagesize ();
619- uint8 preallocated_buf[BUF_SIZE] = {}, preallocated_buf2[BUF_SIZE] = {};
674+ uint8 *preallocated_buf = nullptr ;
675+ uint8 *preallocated_buf2 = nullptr ;
620676 uint64 start1, end1, start2, end2;
621677
678+ preallocated_buf = (uint8_t *)malloc (BUF_SIZE);
679+ ASSERT_NE (preallocated_buf, nullptr );
680+
681+ preallocated_buf2 = (uint8_t *)malloc (BUF_SIZE);
682+ ASSERT_NE (preallocated_buf2, nullptr );
683+
622684 create_test_shared_heap_chain (preallocated_buf, BUF_SIZE, preallocated_buf2,
623685 BUF_SIZE, &shared_heap_chain);
624686
@@ -657,15 +719,24 @@ TEST_F(shared_heap_test, test_shared_heap_chain_memory64_rmw)
657719 " read_modify_write_8" , 3 , argv);
658720 EXPECT_EQ (0 , argv[0 ]);
659721 EXPECT_EQ (preallocated_buf2[BUF_SIZE - 1 ], 81 );
722+
723+ free (preallocated_buf);
724+ free (preallocated_buf2);
660725}
661726
662727TEST_F (shared_heap_test, test_shared_heap_chain_memory64_rmw_oob)
663728{
664729 WASMSharedHeap *shared_heap_chain = nullptr ;
665730 uint32 argv[3 ] = {}, BUF_SIZE = os_getpagesize ();
666- uint8 preallocated_buf[BUF_SIZE], preallocated_buf2[BUF_SIZE];
731+ uint8 *preallocated_buf = nullptr ;
732+ uint8 *preallocated_buf2 = nullptr ;
667733 uint64 start1, end1, start2, end2;
668734
735+ preallocated_buf = (uint8_t *)malloc (BUF_SIZE);
736+ ASSERT_NE (preallocated_buf, nullptr );
737+ preallocated_buf2 = (uint8_t *)malloc (BUF_SIZE);
738+ ASSERT_NE (preallocated_buf2, nullptr );
739+
669740 create_test_shared_heap_chain (preallocated_buf, BUF_SIZE, preallocated_buf2,
670741 BUF_SIZE, &shared_heap_chain);
671742
@@ -689,6 +760,8 @@ TEST_F(shared_heap_test, test_shared_heap_chain_memory64_rmw_oob)
689760 " test64_chain.aot" ,
690761 " read_modify_write_16" , 3 , argv),
691762 " Exception: out of bounds memory access" );
763+ free (preallocated_buf);
764+ free (preallocated_buf2);
692765}
693766#endif
694767
@@ -755,7 +828,8 @@ TEST_F(shared_heap_test, test_addr_conv_pre_allocated_oob)
755828 WASMSharedHeap *shared_heap = nullptr ;
756829 uint32 argv[1 ] = {}, BUF_SIZE = os_getpagesize (),
757830 app_addr = 0xFFFFFFFF - BUF_SIZE;
758- uint8 preallocated_buf[BUF_SIZE];
831+ uint8 *preallocated_buf = (uint8_t *)malloc (BUF_SIZE);
832+ ASSERT_NE (preallocated_buf, nullptr );
759833 bool ret = false ;
760834
761835 /* create a preallocated shared heap */
@@ -787,6 +861,8 @@ TEST_F(shared_heap_test, test_addr_conv_pre_allocated_oob)
787861 " test_addr_conv_chain.aot" ,
788862 " test_preallocated" , 1 , argv),
789863 " Exception: out of bounds memory access" );
864+
865+ free (preallocated_buf);
790866}
791867
792868TEST_F (shared_heap_test, test_shared_heap_chain)
@@ -795,7 +871,8 @@ TEST_F(shared_heap_test, test_shared_heap_chain)
795871 WASMSharedHeap *shared_heap = nullptr , *shared_heap2 = nullptr ,
796872 *shared_heap_chain = nullptr ;
797873 uint32 argv[1 ] = {}, BUF_SIZE = os_getpagesize ();
798- uint8 preallocated_buf[BUF_SIZE];
874+ uint8 *preallocated_buf = (uint8_t *)malloc (BUF_SIZE);
875+ ASSERT_NE (preallocated_buf, nullptr );
799876 bool ret = false ;
800877
801878 ret = wasm_native_register_natives (" env" , g_test_native_symbols,
@@ -830,6 +907,8 @@ TEST_F(shared_heap_test, test_shared_heap_chain)
830907
831908 test_shared_heap (shared_heap, " test_addr_conv.aot" , " test" , 0 , argv);
832909 EXPECT_EQ (1 , argv[0 ]);
910+
911+ free (preallocated_buf);
833912}
834913
835914TEST_F (shared_heap_test, test_shared_heap_chain_create_fail)
@@ -861,7 +940,8 @@ TEST_F(shared_heap_test, test_shared_heap_chain_create_fail2)
861940 WASMSharedHeap *shared_heap = nullptr , *shared_heap2 = nullptr ,
862941 *shared_heap_chain = nullptr ;
863942 uint32 argv[1 ] = {}, BUF_SIZE = os_getpagesize ();
864- uint8 preallocated_buf[BUF_SIZE];
943+ uint8 *preallocated_buf = (uint8_t *)malloc (BUF_SIZE);
944+ ASSERT_NE (preallocated_buf, nullptr );
865945 struct ret_env tmp_module_env;
866946
867947 args.size = 1024 ;
@@ -895,6 +975,8 @@ TEST_F(shared_heap_test, test_shared_heap_chain_create_fail2)
895975
896976 wasm_runtime_detach_shared_heap (tmp_module_env.wasm_module_inst );
897977 destroy_module_env (tmp_module_env);
978+
979+ free (preallocated_buf);
898980}
899981
900982TEST_F (shared_heap_test, test_shared_heap_chain_create_fail3)
@@ -903,7 +985,10 @@ TEST_F(shared_heap_test, test_shared_heap_chain_create_fail3)
903985 WASMSharedHeap *shared_heap = nullptr , *shared_heap2 = nullptr ,
904986 *shared_heap3 = nullptr , *shared_heap_chain = nullptr ;
905987 uint32 argv[1 ] = {}, BUF_SIZE = os_getpagesize ();
906- uint8 preallocated_buf[BUF_SIZE], preallocated_buf2[BUF_SIZE];
988+ uint8 *preallocated_buf = (uint8_t *)malloc (BUF_SIZE);
989+ uint8 *preallocated_buf2 = (uint8_t *)malloc (BUF_SIZE);
990+ ASSERT_NE (preallocated_buf, nullptr );
991+ ASSERT_NE (preallocated_buf2, nullptr );
907992
908993 args.size = 1024 ;
909994 shared_heap = wasm_runtime_create_shared_heap (&args);
@@ -940,6 +1025,9 @@ TEST_F(shared_heap_test, test_shared_heap_chain_create_fail3)
9401025 shared_heap_chain =
9411026 wasm_runtime_chain_shared_heaps (shared_heap2, shared_heap);
9421027 EXPECT_EQ (shared_heap_chain, nullptr );
1028+
1029+ free (preallocated_buf);
1030+ free (preallocated_buf2);
9431031}
9441032
9451033TEST_F (shared_heap_test, test_shared_heap_chain_unchain)
@@ -948,7 +1036,10 @@ TEST_F(shared_heap_test, test_shared_heap_chain_unchain)
9481036 WASMSharedHeap *shared_heap = nullptr , *shared_heap2 = nullptr ,
9491037 *shared_heap3 = nullptr , *shared_heap_chain = nullptr ;
9501038 uint32 argv[1 ] = {}, BUF_SIZE = os_getpagesize ();
951- uint8 preallocated_buf[BUF_SIZE], preallocated_buf2[BUF_SIZE];
1039+ uint8 *preallocated_buf = (uint8_t *)malloc (BUF_SIZE);
1040+ uint8 *preallocated_buf2 = (uint8_t *)malloc (BUF_SIZE);
1041+ ASSERT_NE (preallocated_buf, nullptr );
1042+ ASSERT_NE (preallocated_buf2, nullptr );
9521043
9531044 args.size = 1024 ;
9541045 shared_heap = wasm_runtime_create_shared_heap (&args);
@@ -992,6 +1083,9 @@ TEST_F(shared_heap_test, test_shared_heap_chain_unchain)
9921083 /* break down the entire shared heap chain */
9931084 EXPECT_EQ (shared_heap2,
9941085 wasm_runtime_unchain_shared_heaps (shared_heap_chain, true ));
1086+
1087+ free (preallocated_buf);
1088+ free (preallocated_buf2);
9951089}
9961090
9971091TEST_F (shared_heap_test, test_shared_heap_chain_reset_runtime_managed)
@@ -1003,7 +1097,8 @@ TEST_F(shared_heap_test, test_shared_heap_chain_reset_runtime_managed)
10031097 uint64 offset = 0 , offset_after_reset = 0 ;
10041098 void *native_ptr = nullptr , *native_ptr_after_reset = nullptr ;
10051099 uint32 argv[1 ] = {}, BUF_SIZE = os_getpagesize ();
1006- uint8 preallocated_buf[BUF_SIZE];
1100+ uint8 *preallocated_buf = (uint8_t *)malloc (BUF_SIZE);
1101+ ASSERT_NE (preallocated_buf, nullptr );
10071102 struct ret_env tmp_module_env;
10081103
10091104 args.size = 4096 ;
@@ -1074,14 +1169,17 @@ TEST_F(shared_heap_test, test_shared_heap_chain_reset_runtime_managed)
10741169
10751170 wasm_runtime_detach_shared_heap (tmp_module_env.wasm_module_inst );
10761171 destroy_module_env (tmp_module_env);
1172+
1173+ free (preallocated_buf);
10771174}
10781175
10791176TEST_F (shared_heap_test, test_shared_heap_chain_reset_preallocated)
10801177{
10811178 SharedHeapInitArgs args = {};
10821179 WASMSharedHeap *shared_heap = nullptr ;
10831180 uint32 BUF_SIZE = os_getpagesize ();
1084- uint8 preallocated_buf[BUF_SIZE];
1181+ uint8 *preallocated_buf = (uint8_t *)malloc (BUF_SIZE);
1182+ ASSERT_NE (preallocated_buf, nullptr );
10851183 uint8 set_val = 0xA5 ;
10861184
10871185 args.pre_allocated_addr = preallocated_buf;
@@ -1101,6 +1199,8 @@ TEST_F(shared_heap_test, test_shared_heap_chain_reset_preallocated)
11011199 for (uint32 i = 0 ; i < BUF_SIZE; i++) {
11021200 EXPECT_EQ (0 , preallocated_buf[i]);
11031201 }
1202+
1203+ free (preallocated_buf);
11041204}
11051205
11061206TEST_F (shared_heap_test, test_shared_heap_chain_reset_attached_fail)
@@ -1142,7 +1242,8 @@ TEST_F(shared_heap_test, test_shared_heap_chain_addr_conv)
11421242 WASMSharedHeap *shared_heap = nullptr , *shared_heap2 = nullptr ,
11431243 *shared_heap_chain = nullptr ;
11441244 uint32 argv[1 ] = {}, BUF_SIZE = os_getpagesize ();
1145- uint8 preallocated_buf[BUF_SIZE];
1245+ uint8 *preallocated_buf = (uint8_t *)malloc (BUF_SIZE);
1246+ ASSERT_NE (preallocated_buf, nullptr );
11461247 bool ret = false ;
11471248
11481249 ret = wasm_native_register_natives (" env" , g_test_native_symbols,
@@ -1191,6 +1292,8 @@ TEST_F(shared_heap_test, test_shared_heap_chain_addr_conv)
11911292 test_shared_heap (shared_heap, " test_addr_conv_chain.aot" ,
11921293 " test_preallocated" , 1 , argv);
11931294 EXPECT_EQ (1 , argv[0 ]);
1295+
1296+ free (preallocated_buf);
11941297}
11951298
11961299TEST_F (shared_heap_test, test_shared_heap_chain_addr_conv_oob)
@@ -1199,7 +1302,8 @@ TEST_F(shared_heap_test, test_shared_heap_chain_addr_conv_oob)
11991302 WASMSharedHeap *shared_heap = nullptr , *shared_heap2 = nullptr ,
12001303 *shared_heap_chain = nullptr ;
12011304 uint32 argv[1 ] = {}, BUF_SIZE = os_getpagesize ();
1202- uint8 preallocated_buf[BUF_SIZE];
1305+ uint8 *preallocated_buf = (uint8_t *)malloc (BUF_SIZE);
1306+ ASSERT_NE (preallocated_buf, nullptr );
12031307 bool ret = false ;
12041308
12051309 ret = wasm_native_register_natives (" env" , g_test_native_symbols,
@@ -1242,4 +1346,6 @@ TEST_F(shared_heap_test, test_shared_heap_chain_addr_conv_oob)
12421346 " test_addr_conv_chain.aot" ,
12431347 " test_preallocated" , 1 , argv),
12441348 " Exception: out of bounds memory access" );
1349+
1350+ free (preallocated_buf);
12451351}
0 commit comments