<div dir="ltr">On 5 October 2013 23:29, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im"><span style="color:rgb(34,34,34)"> 2. A function that we call may throw, longjmp, etc. making the code after it potentially unreachable. This affects the 'free on all exit paths' condition. So we need to way to recognize safe functions in this regard (maybe 'always_returns'?).</span></div>
</blockquote><div></div></div><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Hi Hal,</div><div class="gmail_extra"><br></div><div class="gmail_extra">It's not that the code is unreachable (which could be fixed by freeing on all accessible landing pads), it's that people may use the fact that it's unreachable as a feature.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">void check() {</div><div class="gmail_extra">  if (IamSilly)</div><div class="gmail_extra">      throw();</div><div class="gmail_extra">}</div><div class="gmail_extra">
<br></div><div class="gmail_extra">void prepare(void *p) {</div><div class="gmail_extra">  p = malloc(whatever);</div><div class="gmail_extra">  ...</div><div class="gmail_extra">  check();</div><div class="gmail_extra">  ...</div>
<div class="gmail_extra">  free(p);<br></div><div class="gmail_extra">}</div><div class="gmail_extra"><br></div><div class="gmail_extra">void stuff(void *p) {</div><div class="gmail_extra">  if (p)</div><div class="gmail_extra">
    use(p);</div><div class="gmail_extra">}</div><div class="gmail_extra"><br></div><div class="gmail_extra">void cleanup(void *p) {</div><div class="gmail_extra">  if (p)</div><div class="gmail_extra">    free(p);</div><div class="gmail_extra">
}</div><div class="gmail_extra"><br></div><div class="gmail_extra">If you add frees to the landing pads as a safety mechanism, stuff(p); won't work as "expected". I have seen a lot of code that uses exception handling as control-flow mechanism, and they would probably all fail if you try to be smart around a throw.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">cheers,</div><div class="gmail_extra">--renato</div><div class="gmail_extra"><br></div><div class="gmail_extra">PS: Not that I don't want them to fail, but...</div>
</div>