<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/120586>120586</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[analyzer] Wrong warning location of memory leak
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mvpant
</td>
</tr>
</table>
<pre>
```c
// clang --analyze -Xanalyzer -analyzer-output=text
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
void leak(bool v1) {
void* v3 = malloc(1);
if (v3 != NULL) {
int v5 = 0; // <--- warning: Potential leak of memory pointed to by 'v3' [unix.Malloc]
if (v1) {
return; // <--- Expected warning location
}
}
return;
}
void leak2(bool v1) {
void* v3 = malloc(1);
if (v3 != NULL) {
if (v1) { // <--- warning: Potential leak of memory pointed to by 'v3' [unix.Malloc]
return; // <--- Expected warning location
}
}
return;
}
void caller() {
leak(1);
leak2(1);
return;
}
```
[Godbolt example](https://godbolt.org/z/8qGP347Yv)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8VMFymzAQ_ZrlsoMHVmDDgYMdh1zSTi6dtkchFKxWSBQEsfP1HWGcOk16TGc8I4_e7tu3D-3yYVCNkbKAdAfpPuCjO9i-aKeOGxdUtj4VsI7OPwHRFqgEKlFobhoMQ264Pj1LDL8t_3q83PWhHV03OmB7J4_O5_p0pozQYy0R2M3gamXc6gDs9j1Mq-qfWGWtfgGj7WRVjVryn0CZh3CKgXKEzQ6iLaKHgbY4MQS2x5ZrbQVQ5oOAnWPUIwJlPoJiH_T5y_39NQeiMg6ndGaIgO1w8QLYTRiG-MR7o0wDbIsP1knjFNezJLSP2MrW9ifsrDJO1ugsVicE2kwMaIOQ7kajjqtPZ13p_lLwLCl-LQOxl27szVsJt8dOCs-_aEFtBXfKmiUTNmfmy_nC402c766tpA_18nVrH-_l_3BNcK1lD5Rd9bo8ymt3LuZe371Dehm7ZXLS3Z2tK6sdyiNvOy19b5QdnOsGYMtgNueQle0boPIZqMx-3T2wZPN9AsqDumB1znIeyCLesGQd51FOwaEQnImKZUzU64Tn6yRKqyRZ52mSioRFLApUQRElMcV5nLAsplUu87jKUpHXOato8whJJFuu9ErrqfXlAzUMoyxiitJsHWheST3MS4bIyCecUSDyO6cvfFJYjc0ASaTV4IY_NE45PW-ny1qBdI9fe2uaN9_r6nF4i4Ox18Vf9ih3GKuVsC1Q6UssR9j19ocUDqichQ1A5aJ8Kuh3AAAA___Ennwo">