@@ -371,6 +371,72 @@ test_mixed_alloc_many(void **state)
371371 mem_allocator_destroy (allocator );
372372}
373373
374+ /* Test: free a .ro data */
375+ static void
376+ test_free_ro_data (void * * state )
377+ {
378+
379+ mem_allocator_t allocator ;
380+ char heap_buf [64 * 1024 ];
381+ void * ptr ;
382+
383+ allocator = mem_allocator_create (heap_buf , sizeof (heap_buf ));
384+ assert_non_null (allocator );
385+
386+ /* Freeing a .ro data pointer should not crash */
387+ const char * ro_str = "This is a read-only string." ;
388+ // FIXME: This case should trigger an exception because the pointer is not
389+ // allocated by the allocator, but currently it just does nothing. We should
390+ // add a check in mem_allocator_free to detect this case and return an
391+ // error. mem_allocator_free(allocator, (void *)ro_str);
392+ mem_allocator_destroy (allocator );
393+ }
394+
395+ /* Test: free a freed pointer */
396+ static void
397+ test_free_freed_pointer (void * * state )
398+ {
399+ mem_allocator_t allocator ;
400+ char heap_buf [64 * 1024 ];
401+ void * ptr ;
402+
403+ allocator = mem_allocator_create (heap_buf , sizeof (heap_buf ));
404+ assert_non_null (allocator );
405+
406+ ptr = mem_allocator_malloc (allocator , 64 );
407+ assert_non_null (ptr );
408+
409+ mem_allocator_free (allocator , ptr );
410+ /* Freeing the same pointer again should not crash */
411+ mem_allocator_free (allocator , ptr );
412+ mem_allocator_free (allocator , ptr );
413+
414+ mem_allocator_destroy (allocator );
415+ }
416+
417+ /* Test: free a freed pointer from aligned-alloc */
418+ static void
419+ test_free_freed_pointer_aligned (void * * state )
420+ {
421+ mem_allocator_t allocator ;
422+ char heap_buf [64 * 1024 ];
423+ void * ptr ;
424+
425+ allocator = mem_allocator_create (heap_buf , sizeof (heap_buf ));
426+ assert_non_null (allocator );
427+
428+ ptr = mem_allocator_malloc_aligned (allocator , 128 , 64 );
429+ assert_non_null (ptr );
430+
431+ mem_allocator_free (allocator , ptr );
432+ /* Freeing the same pointer again should not crash */
433+ mem_allocator_free (allocator , ptr );
434+ mem_allocator_free (allocator , ptr );
435+ mem_allocator_free (allocator , ptr );
436+
437+ mem_allocator_destroy (allocator );
438+ }
439+
374440/* Test: wasm_runtime_aligned_alloc with valid inputs in POOL mode */
375441static void
376442test_wasm_runtime_aligned_alloc_valid (void * * state )
0 commit comments