<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/177558>177558</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
How to perform correct checks for a reference counted dynamic memory api in C
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
fwh-dc
</td>
</tr>
</table>
<pre>
Hi,
I am experimenting in using CSA on the OpenSSL codebase. Particularly I am interested in checking memory leaks, null ptr dereferences, etc.
Regarding memory leaks I was testing the use of annotations, but I get false positives because there are no annotations that supports the concept of reference counted dynamically allocated memory.
Example:
```
int main() {
EVP_CIPHER *cipher = EVP_CIPHER_new();
if (!EVP_CIPHER_up_ref(cipher))
EVP_CIPHER_free(cipher);
...
EVP_CIPHER_free(cipher);
EVP_CIPHER_free(cipher);
}
```
This will report a double free, but is actually correct code.
What is the best way to support such api's? Is it adding an attribute or defining a checker? Can I contribute such checks or would I have to maintain it outside the LLVM codebase?
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyEVF1r4zgU_TXKy6VGlvP54IdM2tBAly3TZfaxXMvXsXZkyUhXzeTfL7LTmW5hWDDY1j3n3G9hjObsiGqx-iJW9wtM3PtQd5f-rtWLxrfX-tEIdRByL-T-BDgA_RgpmIEcG3cG4yDF_HF42YN3wD3BnyO5l5cn0L6lBiMV8IyBjU4Wg73CpGIcU6DI1GYJ3ZP-nlUGGny4giX8HoU6gEvWwsgBWgrUUSCnaTIQ62IO6iudMbSfyXCCC0ZgilOYOawUCXwH6JxnZOPdJNQkhhOciaFDGwlGHw2bN4rQkMbM4Z4CAQYC5z-ygXtkiGkcfeA4udDeaRo5u_kZLmifXM6zvTocjEZrr4DWeo35dA76lsvDDxxGS6Laz_9iLW-P3BvHMKBxQm2F2oHYfBFyD_Dw7fn1cHp-fPgKQu21GXsKIKr7D4ZXR5eZJaqZZDqYDsoPoDS-BuqE2s4aGa12Gf0B0wWi_yBuekVRfArmd9D_RYjN_afEhdz_1ZsIF2MtBMrVBoTWp8YSzCJzG00E1JymAmsfAmmeZvBW3L9zu8zcqIYiwwWvwP69gxCT7gFHI9QmiuoIpwiGAdtpttABMgfTJCbweR474ybDPLwUMuWADk55Ct6Rk-YEiJl18cm2cIIe3yi7zv1kNC478omjaadxg6enb3_8XB9RHRdtXbW7aocLqsvNeleu1bLaLPparcrdGjtVdlRtcU1StpVsyq6s5G6lsV2YWkm1lqWqSilltSmWq2693KllJ5dlRXIrlpIGNLaw9m0ofDgvTIwpu9msVtuFxYZsnK4HpRxdYLIKpfJtEepMumvSOYqltCZy_CXDhi3Vj_6SEx0pdD4Mv9oyl6TzAfD3q_K-0TiafEscFinYumceY94QdRTqeDbcp6bQfhDqmH3fXndj8P-QZqGOU8RRqOMtpbda_RsAAP__HlSfdA">