[Bug c++/14885] New: Improper delete/free of local variables undetected

ndeb at ece dot cmu dot edu gcc-bugzilla@gcc.gnu.org
Thu Apr 8 00:39:00 GMT 2004


#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



More information about the Gcc-bugs mailing list