Hi All,
We are getting few false positive in our project when we use clang SA.
Consider the below code in mylib.c(library) and main.c -
In lib.c
int* myFn(const int* v){ int* k = v; return k; }
In main.c
int* myFn(const int* v); int main() { int* p = (int*)malloc(sizeof(int)); int* k = myFn(p); free(k); return 0; }
in the above code we don't have any memory leak as free(k) free's the memory allocated by malloc.But we get a false positive (memory leak by 'p') here. The problem seems to be that when we encorter myFn(p) which is a lib call we should have marked p as escaped but we dont seem to do so for malloced region for some reason. Any particular reason we only mark ConstPointerEscaped when it is from NewOrNewArrayFamily?
In this patch have modified the checkConstPointerEscape to mark const pointer as escaped even if it is a malloced region.
Please let me know if this is good to commit or if this check was not handled specifically for some reason.
Awaiting your valuable inputs.
Thanks and Regards
Karthik Bhat