| Issue |
83725
|
| Summary |
Clang misses detecting the "use after free" warning found with GCC
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
mushenoy
|
Clang misses to detect the usage of dynamically allocated memory after free.
Sample program:
```
#include <stdio.h>
#include <stdlib.h>
int main () {
int *p = (int *)malloc (sizeof (int));
*p = 10;
printf ("value of int:%d\n", *p);
free (p);
printf ("value of int:%d\n", *p);
return 0;
}
```
Compilation with clang:
No warnings reported
```
# clang -c -Wall use_after_free.c
#
```
Compilation with gcc:
```
# gcc -c -Wall use_after_free.c
use_after_free.c: In function main:
use_after_free.c:10:9: warning: pointer p used after free [-Wuse-after-free]
10 | printf ("value of int:%d\n", *p);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
use_after_free.c:9:9: note: call to free here
9 | free (p);
| ^~~~~~~~
```
Compiler Versions:
```
clang version 16.0.6
gcc (GCC) 13.2.1
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs