[PATCH] Warn about compile-time detected freeing of automatic/static variables (PR c/36970)
Jakub Jelinek
jakub@redhat.com
Wed Jul 30 16:43:00 GMT 2008
On Wed, Jul 30, 2008 at 05:38:15PM +0200, Richard Guenther wrote:
> On Wed, Jul 30, 2008 at 5:31 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> > + arg = get_base_address (TREE_OPERAND (arg, 0));
> > + if (arg == NULL || INDIRECT_REF_P (arg))
>
> I think you miss TARGET_MEM_REF here if you consider
>
> void *p[10];
> ...
> for (;;)
> free (*(p++));
get_base_address returns NULL or a SSA_VAR_P, STRING_CST, CONSTRUCTOR
or INDIRECT_REF_P. If the base address is SSA_VAR_P, STRING_CST or
CONSTRUCTOR, then the free argument is incorrect.
You can't use ++ on an array, so I'm not sure what exactly you mean.
> > + if (SSA_VAR_P (arg))
> > + warning (0, "%Kattempt to free a non-heap object %qD", exp, arg);
> > + else
> > + warning (0, "%Kattempt to free a non-heap object", exp);
>
> Hm, no way to turn this off? Let me suggest -Wfree-static-storage (uh...) ;)
-fno-builtin-free? Do we really need a way to turn this warning off other
than that? If free doesn't free heap storage, then -fno-builtin-free should
be used, otherwise it is just a security risk.
Jakub
More information about the Gcc-patches
mailing list