typedef __typeof(sizeof(int)) size_t;
void *malloc(size_t);
void free(void *);
void *realloc(void *ptr, size_t size);
void *calloc(size_t nmemb, size_t size);
void __attribute((ownership_returns(malloc))) *my_malloc(size_t);
void __attribute((ownership_takes(malloc, 1))) my_free(void *);
void my_freeBoth(void *, void *)
__attribute((ownership_holds(malloc, 1, 2)));
void __attribute((ownership_returns(malloc, 1))) *my_malloc2(size_t);
void __attribute((ownership_holds(malloc, 1))) my_hold(void *);
void __attribute((ownership_holds(malloc, 1)))
__attribute((ownership_holds(malloc, 1)))
__attribute((ownership_holds(malloc, 3))) my_hold2(void *, void *, void *);
void *my_malloc3(size_t);
void *myglobalpointer;
struct stuff {
void *somefield;
};
struct stuff myglobalstuff;
void f1(void) {
int *p = malloc(12);
return; }
void f2(void) {
int *p = malloc(12);
free(p);
free(p); }
void f2_realloc_0(void) {
int *p = malloc(12);
realloc(p,0);
realloc(p,0); }
void f2_realloc_1(void) {
int *p = malloc(12);
int *q = realloc(p,0); }
void naf1(void) {
int *p = my_malloc3(12);
return; }
void n2af1(void) {
int *p = my_malloc2(12);
return; }
void af1(void) {
int *p = my_malloc(12);
return; }
void af1_b(void) {
int *p = my_malloc(12);
}
void af1_c(void) {
myglobalpointer = my_malloc(12); }
void af1_d(void) {
struct stuff mystuff;
mystuff.somefield = my_malloc(12);
}
void af1_e(void **pp) {
*pp = my_malloc(42); }
void af1_f(struct stuff *somestuff) {
somestuff->somefield = my_malloc(12); }
void af1_g(struct stuff **pps) {
*pps = my_malloc(sizeof(struct stuff)); (*pps)->somefield = my_malloc(42); }
void af2(void) {
int *p = my_malloc(12);
my_free(p);
free(p); }
void af2b(void) {
int *p = my_malloc(12);
free(p);
my_free(p); }
void af2c(void) {
int *p = my_malloc(12);
free(p);
my_hold(p); }
void af2d(void) {
int *p = my_malloc(12);
free(p);
my_hold2(0, 0, p); }
void af2e(void) {
int *p = my_malloc(12);
if (!p)
return; free(p); }
void af3(void) {
int *p = my_malloc(12);
my_hold(p);
free(p); }
int * af4(void) {
int *p = my_malloc(12);
my_free(p);
return p; }
int * af5(void) {
int *p = my_malloc(12);
my_hold(p);
return p; }
int *f3(void) {
static int *p = 0;
p = malloc(12);
return p; }
static int *p_f4 = 0;
int *f4(void) {
p_f4 = malloc(12);
return p_f4; }
int *f5(void) {
int *q = malloc(12);
q = realloc(q, 20);
return q; }
void f6(void) {
int *p = malloc(12);
if (!p)
return; else
free(p);
}
void f6_realloc(void) {
int *p = malloc(12);
if (!p)
return; else
realloc(p,0);
}
char *doit2(void);
void pr6069(void) {
char *buf = doit2();
free(buf);
}
void pr6293(void) {
free(0);
}
void f7(void) {
char *x = (char*) malloc(4);
free(x);
x[0] = 'a'; }
void f7_realloc(void) {
char *x = (char*) malloc(4);
realloc(x,0);
x[0] = 'a'; }
void PR6123(void) {
int *x = malloc(11); }
void PR7217(void) {
int *buf = malloc(2); buf[1] = 'c'; }
void mallocCastToVoid(void) {
void *p = malloc(2);
const void *cp = p; free(p);
}
void mallocCastToFP(void) {
void *p = malloc(2);
void (*fp)(void) = p; free(p);
}
char mallocGarbage (void) {
char *buf = malloc(2);
char result = buf[1]; free(buf);
return result;
}
void callocNoFree (void) {
char *buf = calloc(2,2);
return; }
char callocZeroesGood (void) {
char *buf = calloc(2,2);
char result = buf[3]; if (buf[1] == 0) {
free(buf);
}
return result; }
char callocZeroesBad (void) {
char *buf = calloc(2,2);
char result = buf[3]; if (buf[1] != 0) {
free(buf); }
return result; }
void testMultipleFreeAnnotations(void) {
int *p = malloc(12);
int *q = malloc(12);
my_freeBoth(p, q);
}