Ok, I get what you're saying, PreVisit seems the right answer.<br><br><div class="gmail_quote">On Fri, Jul 2, 2010 at 2:41 PM, Jordy Rose <span dir="ltr"><<a href="mailto:jediknil@belkadan.com">jediknil@belkadan.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
<div class="im"><br>
> struct it *  __attribute((ownership_returns(malloc))) foo(void) {<br>
>   struct it *rv = malloc(sizeof(struct it));<br>
>   if (!rv)<br>
>     return NULL; // Does not warn here.<br>
>   char *textString = malloc(128*sizeof(char));<br>
>   if(textString == NULL)<br>
>     free(rv);<br>
>     return NULL; // Warns about a memory leak here<br>
>   rv->s = textString;<br>
>   return rv; // Does NOT warn here<br>
> }<br>
<br>
</div>...the code is just missing braces around the second if -- the second<br>
"return NULL" is unconditional!<br>
<br>
Clang should catch this. Filing a bug. *grin*<br>
</blockquote></div><br><div>D'oh!</div><div><br></div><div>So looking at this version:</div><div><br></div><div><div>void  __attribute((ownership_returns(malloc))) foo2(void) {</div><div>  struct it *rv = malloc(sizeof(struct it));</div>
<div>  if (!rv)</div><div>    return NULL;</div><div>  char *textString = malloc(128*sizeof(char));</div><div>  if(textString == NULL) {</div><div>    free(rv);</div><div>    return NULL;</div><div>  }</div><div>  rv->s = textString;</div>
<div>  return rv; // warns of a leak here</div><div>}</div><div><br></div></div><div>How could I make the assignment before the final return relinquish ownership of the pointer?</div><div><br></div><div>Andrew</div>