diff options
author | David Schleef <ds@schleef.org> | 2001-05-25 23:20:55 +0000 |
---|---|---|
committer | David Schleef <ds@schleef.org> | 2001-05-25 23:20:55 +0000 |
commit | 6072c7f7eabbf6b6f81aa1ee339f4966d0dd9235 (patch) | |
tree | 8b77e334674526708a76945b853ac39d3de1619a /test/malloc/malloc.c | |
parent | fce6446b7eff58d4c910e8938869b431d172db25 (diff) |
Random quick-and-dirty evil malloc checker.
Diffstat (limited to 'test/malloc/malloc.c')
-rw-r--r-- | test/malloc/malloc.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/malloc/malloc.c b/test/malloc/malloc.c new file mode 100644 index 000000000..698ab5e70 --- /dev/null +++ b/test/malloc/malloc.c @@ -0,0 +1,43 @@ + +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> + +#define N_PTRS 1000 +#define N_ALLOCS 10000 +#define MAX_SIZE 0x10000 + +#define random_size() (random()%MAX_SIZE) +#define random_ptr() (random()%N_PTRS) + +int main(int argc,char *argv[]) +{ + void **ptrs; + int i,j; + int size; + + srandom(0x19730929); + + ptrs = malloc(N_PTRS*sizeof(void *)); + + for(i=0;i<N_PTRS;i++){ + ptrs[i]=malloc(random_size()); + } + for(i=0;i<N_ALLOCS;i++){ + j=random_ptr(); + free(ptrs[j]); + + size=random_size(); + ptrs[j]=malloc(size); + if(!ptrs[j]){ + printf("malloc failed! %d\n",i); + } + memset(ptrs[j],0,size); + } + for(i=0;i<N_PTRS;i++){ + free(ptrs[i]); + } + + return 0; +} + |