This is a second try at some attributes that presently only enable the malloc checker to be smarter.  Syntactically, however, the attributes are intended to be more generally useful.<div><br></div><div>The attributes are currently used like this:</div>
<div><br></div><div><div>void __attribute((ownership_takes(malloc, 1))) bar(char * it) {</div><div>  free(it);</div><div>}</div><div><br></div><div>char * __attribute((ownership_returns(malloc, 1))) bar2(size_t i) {</div>
<div>  return (char *) malloc(i);</div><div>}</div></div><div><br></div><div>There is a third called ownership_holds.  The distinction is that ownership_takes does not allow the resource to be used after passing it in, while ownership_holds does.</div>
<div><br></div><div>The first argument is intended to be the name of a type of resource, in this case memory allocated through malloc.  This is the only value currently checked, any other value is silently ignored.</div><div>
<br></div><div>The second argument is an index into the function's argument list, for ownership_returns it is the size of the malloc region, for the others it is the pointer to check.</div><div><br></div><div>In this patch, only one argument per function can be annotated, that still has to be fixed.</div>
<div><br></div><div>Andrew</div><div><br></div><div><br></div>