From 093724bdef6511a41a86051e04fff79b572709ca Mon Sep 17 00:00:00 2001 From: daan Date: Fri, 28 Oct 2022 20:07:31 -0700 Subject: [PATCH] add test file for valgrind integration --- test/test-wrong.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/test-wrong.c diff --git a/test/test-wrong.c b/test/test-wrong.c new file mode 100644 index 00000000..7544b7fd --- /dev/null +++ b/test/test-wrong.c @@ -0,0 +1,34 @@ +#include +#include +#include "mimalloc.h" + +#ifdef USE_STD_MALLOC +# define mi(x) x +#else +# define mi(x) mi_##x +#endif + +int main(int argc, char** argv) { + int* p = mi(malloc)(3*sizeof(int)); + int* q = mi(malloc)(sizeof(int)); + + // undefined access + // printf("undefined: %d\n", *q); + + *q = 42; + + // buffer overflow + // q[1] = 43; + + mi(free)(q); + + // double free + mi(free)(q); + + // use after free + printf("use-after-free: %d\n", *q); + + // leak p + // mi_free(p) + return 0; +} \ No newline at end of file