<div dir="ltr">Dear all,<div><br></div><div>Consider the following hypothetical test cases (using the Integer Set Library objects and annotations) which is passed through the RetainCountChecker.</div><div><br></div><div><div></div><br><div><div class="gmail-hljs gmail-cpp" style="display:block;overflow-x:auto;padding:0.5em;background:rgb(248,248,248)"><div style="font-family:monospace"><font color="#333333"><b>// Case 1</b></font></div><div><font color="#333333" style="font-family:monospace"><b>#define __isl_give </b></font><font color="#333333" face="monospace"><b>__attribute__((cf_returns_retained))</b></font></div><div><font color="#333333" face="monospace"><b>#define __isl_take __attribute__((cf_consumed))</b></font><br></div><div style="font-family:monospace"><font color="#333333"><b><br></b></font></div><div style="font-family:monospace"><font color="#333333"><b>// Declaration of isl_basic_map_cow(). Definition is in another .c file and hence is not visible to the static analyzer.</b></font></div><div><font color="#333333"><font face="monospace">__isl_give isl_basic_map *isl_basic_map_cow(__isl_take isl_basic_map *bmap);</font><br></font></div><div><font color="#333333"><font face="monospace"><br></font></font></div><div><font color="#333333"><font face="monospace"><br></font></font></div><div style="font-family:monospace"><font color="#333333">__</font><span class="gmail-hljs-function"><font color="#333333">isl_give isl_basic_map *</font><font color="#880000"><b>foo</b></font><span class="gmail-hljs-params" style="color:rgb(51,51,51)">(__isl_take isl_basic_map *bmap)</span> </span><font color="#333333">{</font></div><div style="font-family:monospace;color:rgb(51,51,51)"><span class="gmail-Apple-tab-span" style="white-space:pre">       </span>isl_basic_map *temp = bmap;<span class="gmail-Apple-tab-span" style="white-space:pre">   </span></div><div style="font-family:monospace;color:rgb(51,51,51)"><span class="gmail-Apple-tab-span" style="white-space:pre">   </span>bmap = isl_basic_map_cow(bmap);</div><div style="font-family:monospace;color:rgb(51,51,51)"><span class="gmail-Apple-tab-span" style="white-space:pre">    </span><span class="gmail-hljs-built_in" style="color:rgb(57,115,0)">free</span>(bmap);</div><div style="font-family:monospace;color:rgb(51,51,51)"><span class="gmail-Apple-tab-span" style="white-space:pre">   </span>return temp; <b>// Leak warning is raised for 'bmap' here.</b></div><div style="font-family:monospace;color:rgb(51,51,51)">}</div><div style="font-family:monospace;color:rgb(51,51,51)"><br></div><div style="font-family:monospace;color:rgb(51,51,51)"><b>// Case 2</b></div><div style="font-family:monospace;color:rgb(51,51,51)"><div style="color:rgb(34,34,34);font-family:arial,sans-serif"><font color="#333333" style="font-family:monospace"><b>#define __isl_give </b></font><font color="#333333" face="monospace"><b>__attribute__((cf_returns_retained))</b></font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif"><font color="#333333" face="monospace"><b>#define __isl_take __attribute__((cf_consumed))</b></font><br></div><div style="color:rgb(34,34,34)"><font color="#333333"><b><br></b></font></div><div style="color:rgb(34,34,34)"><font color="#333333"><b>// Declaration of isl_basic_map_cow(). </b></font><b style="color:rgb(51,51,51)">Definition is in another .c file and hence is not visible to the static analyzer.</b></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif"><font color="#333333"><font face="monospace">__isl_give isl_basic_map *isl_basic_map_cow(__isl_take isl_basic_map *bmap);</font></font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif"><font color="#333333"><font face="monospace"><br></font></font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif"><font color="#333333"><font face="monospace"><br></font></font></div></div><div style="font-family:monospace;color:rgb(51,51,51)"><div style="color:rgb(34,34,34)"><font color="#333333">__</font><span class="gmail-hljs-function"><font color="#333333">isl_give isl_basic_map *</font><font color="#880000"><b>foo</b></font><span class="gmail-hljs-params" style="color:rgb(51,51,51)">(__isl_take isl_basic_map *bmap)</span> </span><font color="#333333">{</font></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">   </span>isl_basic_map *temp = bmap;<span class="gmail-Apple-tab-span" style="white-space:pre">   </span></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">       </span>bmap = isl_basic_map_cow(bmap);</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span><span class="gmail-hljs-built_in" style="color:rgb(57,115,0)">free</span>(bmap);</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">       </span>return bmap; <b>// Use-after-free warning is raised for 'bmap' here.</b></div><div>}</div></div></div></div><br><div></div></div><div>My question:</div><div><ul><li>Looking at the warnings raised in both the cases. could someone please explain me why is a leak warning being raised in Case 1? isl_basic_map_cow() returns an object with a +1 retain count which is then freed.</li></ul><div><br></div><div>Thank you.</div></div><div><br></div><div><br></div><div>Regards,</div><div>Malhar Thakkar</div><div><br></div></div><div hspace="streak-pt-mark" style="max-height:1px"><img alt="" style="width:0px;max-height:0px;overflow:hidden" src="https://mailfoogae.appspot.com/t?sender=aY3MxM2IxMDMxQGlpdGguYWMuaW4%3D&type=zerocontent&guid=e405b18c-83a3-4ca8-8afd-5e8afb70d787"><font color="#ffffff" size="1">ᐧ</font></div>