This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/36970] New: GCC should display a warning when trying to free a static array
- From: "nair dot sajish at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 30 Jul 2008 07:12:14 -0000
- Subject: [Bug c/36970] New: GCC should display a warning when trying to free a static array
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
On Tue, Jul 01, 2008 at 11:37:05AM +0000, Joseph S. Myers wrote:
> On Tue, 1 Jul 2008, Michael Meissner wrote:
>
> > On Tue, Jul 01, 2008 at 11:50:58AM +0200, Denys Vlasenko wrote:
> > > On Tuesday 01 July 2008 09:24, Sajish V wrote:
> > > > Thanks for the reply, Denys.
> > > > My question was, why doesn't gcc catch it during compilation? It is clear
> > > > that we are trying to free a variable from stack. Shouldn't gcc flag an
> > > > error for this during compilation?
> >
> > It could. Nobody has written the code to do so, and as they say patches are
> > welcome (assuming you have done the paperwork to legally contribute to GCC).
> > Have you filed a feature request via bugzilla so that it can be tracked?
>
> An error is inappropriate; undefined behavior only occurs on execution of
> the call to free, not on compilation of the program. A warning would be
> fine (as would converting the call to free into an abort).
True enough from a standards point of view. Obviously having a warning would
allow some invalid code to be detected at compilation time.
--
Michael Meissner
email: gnu@the-meissners.org
http://www.the-meissners.org
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
Thanks for the reply, Denys.
My question was, why doesn't gcc catch it during compilation? It is clear that
we are trying to free a variable from stack. Shouldn't gcc flag an error for
this during compilation?
Regards,
Sajish.
----- Original Message ----
From: Denys Vlasenko <vda.linux@googlemail.com>
To: gcc@gcc.gnu.org
Cc: Sajish V <emailsaju@yahoo.com>
Sent: Tuesday, July 1, 2008 2:44:06 PM
Subject: Re: free (static_array)
On Tuesday 01 July 2008 08:38, Sajish V wrote:
> Hi All,
> Can you please let me know why GCC does not crib when we try to free a static array?
> main ()
> {
> char array[100];
> free (array);
> }
> The above code compiles without any hitch.
> Thanks,
> Sajish.
# ./a.out
*** glibc detected *** ./a.out: free(): invalid pointer: 0xffa8b530 ***
======= Backtrace: =========
/lib/libc.so.6[0xf7ecb7a7]
/lib/libc.so.6(__libc_free+0x79)[0xf7ecc0ad]
./a.out[0x804834e]
/lib/libc.so.6(__libc_start_main+0x138)[0xf7e8da74]
./a.out[0x80482b5]
======= Memory map: ========
08048000-08049000 r-xp 00000000 08:06 1315925
/.local/tmp/a.out
08049000-0804a000 rwxp 00000000 08:06 1315925
/.local/tmp/a.out
0804a000-0806b000 rwxp 0804a000 00:00 0 [heap]
f7e6f000-f7e76000 r-xp 00000000 08:05 46193
/app/gcc-3.3.3/lib/libgcc_s.so.1
f7e76000-f7e77000 rwxp 00006000 08:05 46193
/app/gcc-3.3.3/lib/libgcc_s.so.1
f7e77000-f7e78000 rwxp f7e77000 00:00 0
f7e78000-f7f60000 r-xp 00000000 08:0
--
vda
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
Hi All,
Can you please let me know why GCC does not crib when we try to free a static
array?
main ()
{
char array[100];
free (array);
}
The above code compiles without any hitch.
Thanks,
Sajish.
--
Summary: GCC should display a warning when trying to free a
static array
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: nair dot sajish at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36970