free(a);// expected-warning {{Argument to free() is the address of the local variable 'a', which is not memory allocated by malloc()}}
}
voidt2(){
inta=1;
free(&a);// expected-warning {{Argument to free() is the address of the local variable 'a', which is not memory allocated by malloc()}}
}
voidt3(){
staticinta[]={1};
free(a);// expected-warning {{Argument to free() is the address of the static variable 'a', which is not memory allocated by malloc()}}
}
voidt4(char*x){
free(x);// no-warning
}
voidt5(){
externchar*ptr();
free(ptr());// no-warning
}
voidt6(){
free((void*)1000);// expected-warning {{Argument to free() is a constant address (1000), which is not memory allocated by malloc()}}
}
voidt7(char**x){
free(*x);// no-warning
}
voidt8(char**x){
// ugh
free((*x)+8);// no-warning
}
voidt9(){
label:
free(&&label);// expected-warning {{Argument to free() is the address of the label 'label', which is not memory allocated by malloc()}}
}
voidt10(){
free((void*)&t10);// expected-warning {{Argument to free() is the address of the function 't10', which is not memory allocated by malloc()}}
}
voidt11(){
char*p=(char*)__builtin_alloca(2);
free(p);// expected-warning {{Argument to free() was allocated by alloca(), not malloc()}}
}
voidt12(){
free(^{return;});// expected-warning {{Argument to free() is a block, which is not memory allocated by malloc()}}
}
voidt13(chara){
free(&a);// expected-warning {{Argument to free() is the address of the parameter 'a', which is not memory allocated by malloc()}}
}
staticintsomeGlobal[2];
voidt14(){
free(someGlobal);// expected-warning {{Argument to free() is the address of the global variable 'someGlobal', which is not memory allocated by malloc()}}