[cfe-dev] Static analyzer: possible memory leak false positive?

Anna Zaks ganna at apple.com
Fri Sep 14 10:54:52 PDT 2012

I think it is reasonable to expect the analyzer not to warn in this particular case.

However, constructing a rule on when the error should be suppressed is tricky. One possibility is that the analyzer should dismiss the warning only if it can prove that nothing allocates memory after the leak. For example, if main calls foo() after the leak is detected, we should warn, unless we can prove that foo() does not allocate memory. This rule would silence the warning in this case, but might not work in case where foo() is called after the leak and the analyzer does not know what the effect of foo()  will be.

Joerg, I think that, since the analyzer looks at preprocessed code, redefinition of main would not be an issue.

On Sep 14, 2012, at 2:15 AM, Erik Cederstrand <erik at cederstrand.dk> wrote:

> Hi all,
> Before spamming Bugzilla, I'd like an opinion on this possible false positive in the static analyzer.
> See http://scan.freebsd.your.org/freebsd-head/bin.df/2012-09-12-amd64/report-WwB2qk.html#EndPath
> The analyzer is complaining about a memory leak of mntbuf two lines before the end of the main() function.
> I'm not sure this is actually a false positive since it relies on the implicit behavior that the OS reclaims the memory regardless, but the warning does seem of minor value.
> Kind regards,
> Erik Cederstrand
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

More information about the cfe-dev mailing list