<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/83725>83725</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang misses detecting the "use after free" warning found with GCC
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mushenoy
</td>
</tr>
</table>
<pre>
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
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVM2OozgQfhpzKQVBOYRw4JAmk9Fe9rLSznFkcAFeGRvZpkfZwz77ypDJdE-new87CBmoKr76-6qE92owRDUrnlhxTsQSRuvqafEjGXtNWiuvdaOFGWBS3pOHYEFSoC5AGAkWLwYC24O8GjGpTmh9BaG17UQgCRNN1l1B9IEc9I4oZdmZZaft_ENMsyaYnR2cmBi_idkhu93bJ3JlOr1IAsYbH6Sy6cj4p3e0WrUv1eupTIBJKAMMjwwrYOXTpoDbFQ0YnmZg_ByNbt8Mq2lNJsq8-ptsf9MyrOLNf8K5Y-TZXffaYnbKhH4LBJ-FXtbqRUR-YlhIVjSGITJsVrBHTmIdI8BD5f_BdxQWZ-BF6OX5cUvWs7HTrLQIyhr4psIIXeTJvY2_W_gmnFFm8OBoti6QfK_B268Auw52X4TWsHj6urLm68qa7m75EOFNJEPXfUCnqP4vV2-k_AS_GegX061uIp3uLh4YRwKcqvjXrQjxdbbKxEmYo1P5YiyAFU-7L4un3SrbRRkrzvfW5hmwsoFfRqIIxopP_3x8vZtc9T03YwPFZ5z7uBnWXEZy9MNZ9SryD7j7OqYP-kwO_iTnlTX-vSZvdHrerCA_pFl6gE0Ve8_w-Llp4ibIeYpp_hNGImsuK16JhOq8zKp9WRT7MhnrtuwPgudyX2J7lBlyjjnmneyxRJRdlqgaM9xnPOP5Pq-yMpX7rpfykPGjJGzznu0zmoTSqdbPU2rdkCjvF6qPvMQi0aIl7dddjLhNE2Jcy66O9rt2GTzbZ1r54H8gBBU0vV7S24ZWZliXNENcPL2gG0P8Tkvo7WLkNjWfmwaSxel6DGFea4sXhpdBhXFp085ODC_R6-2xm539i7rA8LIm4Rle1jz-DQAA__8KOtO7">