Bug 466762 - Add redirs for C23 free_sized() and free_aligned_sized()
[valgrind.git] / memcheck / tests / malloc_free_fill.c
blob35a4ae3ce3553a321ef415f21f878adf08d6a295
2 /* Test for correct functioning of the --malloc-fill and --free-fill
3 flags. Needs --malloc-fill=0x55 and --free-fill=0x77. */
5 #include <stdio.h>
6 #include <assert.h>
7 #include <stdlib.h>
8 #include "../memcheck.h"
10 int main ( void )
12 int *r, *oldr, *a;
14 #define TEST(x, exp_x, desc) \
15 (void)VALGRIND_MAKE_MEM_DEFINED(&x, sizeof(int)); \
16 if (x == exp_x) { \
17 fprintf(stderr, "PASSED: " desc "\n"); \
18 } else { \
19 fprintf(stderr, "FAILED: " desc "\n"); \
22 //-------------------------------------------------------------
23 fprintf(stderr, "test simple malloc/free:\n");
25 a = malloc(10 * sizeof(int)); assert(a);
26 TEST(a[4], 0x55555555, "malloc-filled");
28 free(a);
29 TEST(a[5], 0x77777777, " free-filled");
31 //-------------------------------------------------------------
32 fprintf(stderr, "\ntest realloc-larger:\n");
34 r = malloc(30 * sizeof(int)); assert(r);
35 TEST(r[25], 0x55555555, "malloc-filled");
37 /* Make larger */
38 oldr = r;
39 r = realloc(r, 40 * sizeof(int)); assert(r);
41 TEST(oldr[26], 0x77777777, " free-filled");
42 TEST( r[35], 0x55555555, "malloc-filled");
44 free(r);
46 //-------------------------------------------------------------
47 fprintf(stderr, "\ntest realloc-smaller:\n");
49 r = malloc(30 * sizeof(int)); assert(r);
50 TEST(r[25], 0x55555555, "malloc-filled");
52 /* Make smaller */
53 oldr = r;
54 r = realloc(r, 20 * sizeof(int)); assert(r);
56 TEST(oldr[26], 0x77777777, " free-filled");
58 free(r);
60 //-------------------------------------------------------------
61 fprintf(stderr, "\ntest calloc:\n");
62 a = calloc(100, sizeof(int)); assert(r);
64 TEST(a[42], 0x00000000, "zero");
66 free(a);
68 return 0;