summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFrank Richter <frank.richter@gmail.com>2021-12-19 21:57:06 +0100
committerFrank Richter <frank.richter@gmail.com>2021-12-21 16:20:59 +0100
commit691eb0d8edc17fbb4850a704244fed302282f931 (patch)
tree44c5dccfedbc7b2e6862b4cdac668a075a24fc22 /test
parent1cf7ca021da6535df41746b3d9445571c7a0ebc2 (diff)
Add tests to check "freed memory fill" behaviour in debug mode
Diffstat (limited to 'test')
-rw-r--r--test/test-api-fill.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/test-api-fill.c b/test/test-api-fill.c
index 39f6f88..0e5a65d 100644
--- a/test/test-api-fill.c
+++ b/test/test-api-fill.c
@@ -15,6 +15,7 @@ terms of the MIT license. A copy of the license can be found in the file
bool check_zero_init(uint8_t* p, size_t size);
#if MI_DEBUG >= 2
bool check_debug_fill_uninit(uint8_t* p, size_t size);
+bool check_debug_fill_freed(uint8_t* p, size_t size);
#endif
// ---------------------------------------------------------------------------
@@ -269,6 +270,22 @@ int main(void) {
result &= check_debug_fill_uninit(p, malloc_size);
mi_free(p);
});
+
+
+ CHECK_BODY("fill-freed-small", {
+ size_t malloc_size = MI_SMALL_SIZE_MAX / 2;
+ uint8_t* p = (uint8_t*)mi_malloc(malloc_size);
+ mi_free(p);
+ // First sizeof(void*) bytes will contain housekeeping data, skip these
+ result = check_debug_fill_freed(p + sizeof(void*), malloc_size - sizeof(void*));
+ });
+ CHECK_BODY("fill-freed-large", {
+ size_t malloc_size = MI_SMALL_SIZE_MAX * 2;
+ uint8_t* p = (uint8_t*)mi_malloc(malloc_size);
+ mi_free(p);
+ // First sizeof(void*) bytes will contain housekeeping data, skip these
+ result = check_debug_fill_freed(p + sizeof(void*), malloc_size - sizeof(void*));
+ });
#endif
// ---------------------------------------------------
@@ -301,4 +318,15 @@ bool check_debug_fill_uninit(uint8_t* p, size_t size) {
}
return result;
}
+
+bool check_debug_fill_freed(uint8_t* p, size_t size) {
+ if(!p)
+ return false;
+
+ bool result = true;
+ for (size_t i = 0; i < size; ++i) {
+ result &= p[i] == MI_DEBUG_FREED;
+ }
+ return result;
+}
#endif