blob: 698ab5e70b6a9b51dd65d26d64a6f76a13d492de (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;
}
|