<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/79329>79329</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Analyzer claims to have found potential memory leak, yet it clearly is not a leak
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          CodingMarkus
      </td>
    </tr>
</table>

<pre>
    According to clang analyzer, the following code is a potential leak:

```
guard_C (certRef, SecCertificateCreateWithData(NULL, derData)) else return nil;
__auto_type const instance = [self initWithCertificate:certRef];
CFRelease(certRef);
return instance;
```

The `guard_C` macro expands as follows:

```
__auto_type const v_217 = (SecCertificateCreateWithData(NULL, derData)); 
__auto_type const n_217 = (typeof(* v_217) *_Nonnull)1; 
__auto_type const certRef = (!v_217 ? n_217 : (typeof(* v_217) *_Nonnull)v_217); 
if (certRef != n_217) { } else return nil;
```

This is clearly not a leak. `return nil` is only executed if `SecCertificateCreateWithData()` returned `NULL`.  

More precisely, it is only executed if `certRef == n_217` and that is only the case if `v_217` is `NULL`. 

If `v_217` is not `NULL`, `certRef == v_217`, so `certRef != n_217` is true, the else part is not executed, the code continues below the if and the result of `SecCertificateCreateWithData()` is released.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVF2v2zYM_TXKC9FAlmMnfvBDPhBgQNuHbsMeA0WiY62KFEj0vc1-_SB_JO4ubrcVCBxYInkOeegjYzQXh1izYseKw0J21PpQ77027vJJhq9dXJy9vtdbpXxIh0AelJXuAtJJe_8LAxN7oBah8db61xSivEYwESTcPKEjIy1YlF9ZvmX8wPj0LPn4618vnQz6tAcmNgoDfcEmVf4V1R4DmcYoSbgPKAn_MNQeJEkmNp9___gxhWkMw0nFRAVoI0JA6oIDZyzLdwPE6SQ78ie63xCUd5HAuEjSKQSWH4AVu4i2AeMMJYwZMMu3E6ni8Ki3P35BizLinHP1uB4ZTBiP8380Pjx_axFYyccpsJLDVargAb_dpNMRZBwnHH88xrc9vpxEth4aFJufmSfLd_BecTcvns59w8SGie0Am9RgYnv67J3rrGWiyn5UbRziVI-JbCJ_fCBt_yvSdPwENM1su4CJLOG4R_Z6B2x9eHd73pHNxLTryqIM9g7OE8h-25dJzlmZkqc47-wd8BuqjlBDIlTyf9EktVDykRHqlNHLVPIlwJzLJx8QbgGViWjvSUZD72HOJv0cQslBOg3Uymde-rSVjDjmvUyBJn5HZM7jlzeRaSrP6MTsLYUpPt1G_13AXKihIIUOJ-Pp9brJQBPS1OoU0PuR8o6M6zDCGa1_7S9MM_ab9I6dJfD_QxATIQyfv14udJ3rKq_kAutszcssK8qsXLR1uZK8KEVTbFaqUVlTVFg0UpWbphLraq0XphZcrHgmVtma84wvdVOtMlWJpshLrcuCrThepbFLa1-uSx8uCxNjh_W6ykW1sPKMNvb-LYTDV-gvmRDJzkOdcj6cu0tkK25NpPisQoYs1tvRxZOpm2tM9t7Kl-TmndMz_77i1Yf7YONiD3ektFzT1o-DHxZ_0QVbt0S33qnEkYnjxVDbnZfKX5k4Jgbj34db8H-iIiaOPe_IxLHv6-8AAAD__9Z9CIk">