public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/14885] New: Improper delete/free of local variables undetected
@ 2004-04-08  0:39 ndeb at ece dot cmu dot edu
  2004-04-08  0:41 ` [Bug c++/14885] " ndeb at ece dot cmu dot edu
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: ndeb at ece dot cmu dot edu @ 2004-04-08  0:39 UTC (permalink / raw)
  To: gcc-bugs

#include <iostream> 
using namespace std; 
int main() 
{ 
int u=3; 
cout << "u = " << u << endl; 
delete &u; 
return 0; 
} 
 
This program compiles (g++ -g file.cpp) ok without any warnings. It seg faults 
at runtime. The cause is very clear since the "delete" operation done by the 
user is followed by the delete performed by the program itself. This leads to 
a double free leading to a seg fault. 
 
Since the program is well-formed, the compiler cannot report a compilation 
error, even if it can detect the possibility of undefined behavior. One way 
out is to give a warning at compile time. 
 
Note that the same problem is there for the C compiler. Also, this problem has 
been reproduced with other g++ versions (2.95.3, 3.2.1) too.

-- 
           Summary: Improper delete/free of local variables undetected
           Product: gcc
           Version: 3.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ndeb at ece dot cmu dot edu
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14885


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-04-11  2:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-08  0:39 [Bug c++/14885] New: Improper delete/free of local variables undetected ndeb at ece dot cmu dot edu
2004-04-08  0:41 ` [Bug c++/14885] " ndeb at ece dot cmu dot edu
2004-04-08  0:48 ` pinskia at gcc dot gnu dot org
2004-04-08 18:43 ` bangerth at dealii dot org
2004-04-08 19:55 ` gdr at integrable-solutions dot net
2004-04-08 20:11 ` ndeb at ece dot cmu dot edu
2004-04-09 19:03 ` bangerth at dealii dot org
2004-04-10  2:36 ` ndeb at ece dot cmu dot edu
2004-04-11 12:39 ` bangerth at dealii dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).