[cfe-dev] RFC: static analysis, malloc annontation for return via pointer argument

Ted Kremenek kremenek at apple.com
Mon Dec 17 15:32:41 PST 2012


On Dec 17, 2012, at 1:55 PM, Scott Parlane <scott at scottnz.com> wrote:

> This patch allows for APIs were memory is allocated and placed in a
> pointer given to them. (like asprintf, but without the realloc feature)

Thanks Scott.  I'm not such a fan of the name of the attribute.  Since this is returning an object by reference, how about ownership_returns_byref?  I'm sure others will have an opinion, but ownership_returns_pointer really doesn't tell the user what this attribute does.

As for the implementation itself, it looks okay.  The annotation support eventually needs to be migrated from the alpha.unix.MallocWithAnnotations checker to the unix.Malloc checker (same file, logic controlled with a flag), but that's a separate issue.

> 
> Currently, when using a pointer to a stack variable as the input to the
> function, it declares the memory leak on the next source line after the
> stack variable is used. I think it should be declaring the leak on the
> last line of the current scope. Which is correct ?

The current behavior is correct.  The current scope could be very big, and may end long after the leak occurs.  We have found that reporting leaks as close as possible to where the leak occurred is a much better experience for users.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121217/dde83ee7/attachment.html>


More information about the cfe-dev mailing list