https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71218

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Marc Glisse from comment #1)
> Can you be more specific? Do you mean people should have written:
> T tab[8];

Yes, exactly. I was fixing some code earlier today that used a dynamically
allocated buffer of 8 chars and deleted it at the end of the function (but
failed to do so on two early return paths). There was no reason it was done
that way instead of using an automatic array, probably just someone who learnt
to programme in Java and didn't know better.

> instead? What if 8 or sizeof(T) is large?

The case I looked at was char, it would probably be OK to only warn for scalar
types, and for small array lengths (for some value of small).

> If your "..." includes possible
> writes to p, or if p escapes and "..." may throw, I guess that cancels the
> warning? At some point the issue becomes similar to optimizing malloc to a
> stack allocation.

Part of the problem in the code I was fixing was that the "..." certainly could
throw, and the delete never happened.

But maybe the escape analysis is too tricky.

Reply via email to