<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/55019>55019</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
False positive: Potential leak of memory [unix.malloc]
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
josephcsible
</td>
</tr>
</table>
<pre>
I'm running version 14.0.0 obtained from https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz
Consider this C program:
```c
#include <stdlib.h>
#include <string.h>
struct mystruct {
void *ptr;
char arr[4];
};
int main(void) {
struct mystruct x;
x.ptr = malloc(1);
strcpy(x.arr, "hi\n");
free(x.ptr);
}
```
When I run `clang --analyze /tmp/bug.c`, I get this:
```
/tmp/bug.c:13:5: warning: Potential leak of memory pointed to by 'x.ptr' [unix.Malloc]
free(x.ptr);
^~~~~~~~~~~
1 warning generated.
```
But it's clear that there's not actually a potential leak of memory here.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVEuP2yAQ_jXkgowwNrFz8CGPXWkPlXrrscI2sdliiHhkk_31HZxNm2y3W9XCY2Be33yMaW1_bp4QqybsojHKDPgonVfW4LwklFBs2yCUkT3eOzvhMYSDR8UasUcYgwpjbElnJ1hofbx-soOzz7ILsHRSS-Glh2lvX4y2on8zsm7ILjlgo9PCDIhtZu_Lbnaql9-XZaaViadsMDGLbTQhZnlNaEmCcOT0iugO0fVFbq3xqpcOh1F5vMUAYnBiSmgvVkt6Gd3bmhXKdDr2EqNi60OvVUtGVDx8rHZAzq16lrAdu4Cn89sEVZuLAsNztKrHiK0PwaHiZr8bhcPCOcQ3JeK7XzpU3cxnqQzEBvoRq1MwxFb3Gd6nP93lORHIDOB3EENr20GUHELc2YBjdziD5kQSIrYFwGxUiG8hKXtvvXdSzrappBtdQn7P8W0V30Zp8FNqMJzYT0eNs0wYoc-vQC57DNMBZBsH0iVXAPGEBxnmg_zz-K7Hc-dWrPMCBIcXvwiXOjlNv9ogTVBCY2jDH9ju8SSh8874YIFb6OpgcXsGDNVbTRWGU4lGnciXC2d89-_ykw7xB1R9OmbT_IoOCjTSCcBAPqxvEwNW8AdVHneAPXW1SIxIJ-dNYwMWXYiA8owF1POXQpMDWfRN0a-KlVgEFbRsHoX2Eny8CuooPyXqSsd0pWMRnW7--x5Q3sf5FuCc5qvF2PCS7intlyAKvhKCVcU-X-4LJmta97RcaNFK7RvID41o5AueQ6SmBAyqYZQxWrI8ryjjNamLuuO5EKXkvJY8RyWV8OdoknAQuGsWrpkhQbt4UGrlg_-tFN6rwUg5p4P4IobRuubZenkYO69aLRdz_mbG_xPp4oxn">