1#include <string.h> 2#include <stdio.h> 3#include <stdlib.h> 4#include <assert.h> 5#include "valgrind.h" 6#include "../memcheck.h" 7 8struct super { int x; }; 9static struct super superblock = { 12345 }; 10 11/* run with `valgrind -q --malloc-fill=0xaf --free-fill=0xdb` */ 12int main(int argc, char **argv) 13{ 14 unsigned char *s; 15 VALGRIND_CREATE_MEMPOOL(&superblock, /*rzB=*/0, /*is_zeroed=*/0); 16 s = malloc(40); 17 assert(s); 18 assert(*s == 0xaf); 19 *s = 0x05; 20 VALGRIND_MEMPOOL_ALLOC(&superblock, s, 40); 21 printf("*s=%#hhx after MEMPOOL_ALLOC\n", *s); 22 VALGRIND_MEMPOOL_FREE(&superblock, s); 23 printf("*s=%#hhx after MEMPOOL_FREE\n", *s); 24 VALGRIND_MEMPOOL_ALLOC(&superblock, s, 40); 25 printf("*s=%#hhx after second MEMPOOL_ALLOC\n", *s); 26 free(s); 27 VALGRIND_DESTROY_MEMPOOL(&superblock); 28 29 s = malloc(40); 30 assert(s); 31 assert(*s == 0xaf); 32 *s = 0x05; 33 VALGRIND_MALLOCLIKE_BLOCK(s, 40, 0/*rzB*/, 0/*is_zeroed*/); 34 printf("*s=%#hhx after MALLOCLIKE_BLOCK\n", *s); 35 VALGRIND_FREELIKE_BLOCK(s, 0/*rzB*/); 36 printf("*s=%#hhx after FREELIKE_BLOCK\n", *s); 37 VALGRIND_MALLOCLIKE_BLOCK(s, 40, 0/*rzB*/, 0/*is_zeroed*/); 38 printf("*s=%#hhx after second MALLOCLIKE_BLOCK\n", *s); 39 40 return 0; 41} 42 43