diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/double-free.c | 19 | ||||
-rw-r--r-- | test/use-after-free.c | 18 |
2 files changed, 37 insertions, 0 deletions
diff --git a/test/double-free.c b/test/double-free.c new file mode 100644 index 0000000..73ceff5 --- /dev/null +++ b/test/double-free.c @@ -0,0 +1,19 @@ +#define _POSIX_C_SOURCE 200809L +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include "mapalloc.h" + +int main(void) +{ + const char buf[] = "THIS IS A CONSTANT STRING"; + + char *ptr = map_malloc(sizeof(buf)); + memcpy(ptr, buf, sizeof(buf)); + printf("%p: %s\n", ptr, ptr); + + map_free(ptr); + printf("freed\n"); + map_free(ptr); + printf("freed again\n"); +} diff --git a/test/use-after-free.c b/test/use-after-free.c new file mode 100644 index 0000000..4338ed5 --- /dev/null +++ b/test/use-after-free.c @@ -0,0 +1,18 @@ +#define _POSIX_C_SOURCE 200809L +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include "mapalloc.h" + +int main(void) +{ + const char buf[] = "THIS IS A CONSTANT STRING"; + + char *ptr = map_malloc(sizeof(buf)); + memcpy(ptr, buf, sizeof(buf)); + printf("%p: %s\n", ptr, ptr); + + map_free(ptr); + printf("freed\n"); + printf("%p: %s\n", ptr, ptr); +} |