public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/39237]  New: Overloaded Operator delete not called
@ 2009-02-18 21:38 caroline dot rioux at ca dot ibm dot com
  2009-02-18 21:39 ` [Bug libstdc++/39237] " caroline dot rioux at ca dot ibm dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: caroline dot rioux at ca dot ibm dot com @ 2009-02-18 21:38 UTC (permalink / raw)
  To: gcc-bugs

Hello,

We use a unit testing framework which overloads operator new and operator
delete to track memory allocations and detect leaks.  According to it, vector's
push_back method allocates memory through operator new but does not release it
through operator delete.

I am not sure if this is because the memory is not released, is not released
through delete, or that the overloaded operator is simply not called.

The simple test case is as follows;

----
#include <vector>
#include <iostream>

int main (int argc, char ** argv) 
{
  {
        std::vector< int > objects;
        objects.push_back(1);
  }
  return 0;
}

static int allocatedBlocks = 0;

void* operator new(size_t size)
{
        allocatedBlocks++;
        void * toReturn = malloc(size);
        std::cerr << "operator new(size = " << size 
                  << "), returns: " << toReturn 
                  << " allocatedBlocks: " << allocatedBlocks << std::endl;
        return toReturn;
}

void operator delete(void* mem)
{
        if(mem == NULL)
          return;
        allocatedBlocks--;
        std::cerr << "operator delete(mem = " << mem << ") allocatedBlocks: "
<< allocatedBlocks << std::endl;
        free(mem);
}
-----

Using gcc 3.2.3, running this program yields the following output:

operator new(size = 320), returns: 0x503010 allocatedBlocks: 1

Using gcc 4.1.2, I get the expected:

operator new(size = 4), returns: 0x503010 allocatedBlocks: 1
operator delete(mem = 0x503010) allocatedBlocks: 0

I read in the FAQ that containers save memory for later re-use, but shouldn't
it be released when the vector goes out of scope? 

Please see the preprocessed source (attached) and the g++ information below.

--------------
/home/riouxc/temp> g++ -v -save-temps simple_vector.cpp 
Reading specs from /isv/gnu/bin/../lib/gcc-lib/x86_64-redhat-linux/3.2.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--enable-languages=c,c++ --disable-libgcj --host=x86_64-redhat-linux
Thread model: posix
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-47.3)
 /isv/gnu/bin/../lib/gcc-lib/x86_64-redhat-linux/3.2.3/cpp0 -lang-c++
-D__GNUG__=3 -D__DEPRECATED -D__EXCEPTIONS -v -iprefix
/isv/gnu/bin/../lib/gcc-lib/x86_64-redhat-linux/3.2.3/ -D__GNUC__=3
-D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=3 -D__GXX_ABI_VERSION=102 -D__ELF__
-Dunix -D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -D__linux__
-D__unix -D__linux -Asystem(posix) -D__NO_INLINE__ -D__STDC_HOSTED__=1
-D_GNU_SOURCE -Acpu=x86_64 -Amachine=x86_64 -D__x86_64 -D__x86_64__
-D__SIZE_TYPE__=unsigned long int -D__PTRDIFF_TYPE__=long int -D__tune_athlon__
-D__tune_athlon_sse__ -D__LONG_MAX__=9223372036854775807L -D__LP64__ -D_LP64
simple_vector.cpp simple_vector.ii
GNU CPP version 3.2.3 20030502 (Red Hat Linux 3.2.3-47.3) (cpplib) (x86-64
Linux/ELF)
ignoring nonexistent directory "/isv/gnu/bin/../x86_64-redhat-linux/include"
ignoring nonexistent directory "/usr/x86_64-redhat-linux/include"
ignoring duplicate directory "/usr/include/c++/3.2.3"
ignoring duplicate directory "/usr/include/c++/3.2.3/x86_64-redhat-linux"
ignoring duplicate directory "/usr/include/c++/3.2.3/backward"
ignoring duplicate directory
"/usr/lib/gcc-lib/x86_64-redhat-linux/3.2.3/include"
#include "..." search starts here:
#include <...> search starts here:
 /isv/gnu/bin/../include/c++/3.2.3
 /isv/gnu/bin/../include/c++/3.2.3/x86_64-redhat-linux
 /isv/gnu/bin/../include/c++/3.2.3/backward
 /isv/gnu/bin/../lib/gcc-lib/x86_64-redhat-linux/3.2.3/include
 /usr/local/include
 /usr/include
End of search list.
 /isv/gnu/bin/../lib/gcc-lib/x86_64-redhat-linux/3.2.3/cc1plus -fpreprocessed
simple_vector.ii -quiet -dumpbase simple_vector.cpp -version -o simple_vector.s
GNU CPP version 3.2.3 20030502 (Red Hat Linux 3.2.3-47.3) (cpplib) (x86-64
Linux/ELF)
GNU C++ version 3.2.3 20030502 (Red Hat Linux 3.2.3-47.3) (x86_64-redhat-linux)
        compiled by GNU C version 3.2.3 20030502 (Red Hat Linux 3.2.3-47.3).
 as -V -Qy -o simple_vector.o simple_vector.s
GNU assembler version 2.15.92.0.2 (x86_64-redhat-linux) using BFD version
2.15.92.0.2 20040927
 /isv/gnu/bin/../lib/gcc-lib/x86_64-redhat-linux/3.2.3/collect2 --eh-frame-hdr
-m elf_x86_64 -Y P,/usr/lib64 -dynamic-linker /lib64/ld-linux-x86-64.so.2
/isv/gnu/bin/../lib/gcc-lib/x86_64-redhat-linux/3.2.3/../../../../lib64/crt1.o
/isv/gnu/bin/../lib/gcc-lib/x86_64-redhat-linux/3.2.3/../../../../lib64/crti.o
/isv/gnu/bin/../lib/gcc-lib/x86_64-redhat-linux/3.2.3/crtbegin.o
-L/isv/gnu/bin/../lib/gcc-lib/x86_64-redhat-linux/3.2.3
-L/isv/gnu/bin/../lib/gcc-lib -L/usr/lib/gcc-lib/x86_64-redhat-linux/3.2.3
-L/isv/gnu/bin/../lib/gcc-lib/x86_64-redhat-linux/3.2.3/../../../../lib64
-L/isv/gnu/bin/../lib/gcc-lib/x86_64-redhat-linux/3.2.3/../../..
-L/usr/lib/gcc-lib/x86_64-redhat-linux/3.2.3/../../../../lib64
-L/usr/lib/gcc-lib/x86_64-redhat-linux/3.2.3/../../.. -L/lib/../lib64
-L/usr/lib/../lib64 simple_vector.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s
-lgcc /isv/gnu/bin/../lib/gcc-lib/x86_64-redhat-linux/3.2.3/crtend.o
/isv/gnu/bin/../lib/gcc-lib/x86_64-redhat-linux/3.2.3/../../../../lib64/crtn.o


-- 
           Summary: Overloaded Operator delete not called
           Product: gcc
           Version: 3.2.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: caroline dot rioux at ca dot ibm dot com


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


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

* [Bug libstdc++/39237] Overloaded Operator delete not called
  2009-02-18 21:38 [Bug libstdc++/39237] New: Overloaded Operator delete not called caroline dot rioux at ca dot ibm dot com
@ 2009-02-18 21:39 ` caroline dot rioux at ca dot ibm dot com
  2009-02-18 21:45 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: caroline dot rioux at ca dot ibm dot com @ 2009-02-18 21:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from caroline dot rioux at ca dot ibm dot com  2009-02-18 21:39 -------
Created an attachment (id=17327)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17327&action=view)
Preprocessed source


-- 


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


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

* [Bug libstdc++/39237] Overloaded Operator delete not called
  2009-02-18 21:38 [Bug libstdc++/39237] New: Overloaded Operator delete not called caroline dot rioux at ca dot ibm dot com
  2009-02-18 21:39 ` [Bug libstdc++/39237] " caroline dot rioux at ca dot ibm dot com
@ 2009-02-18 21:45 ` pinskia at gcc dot gnu dot org
  2009-02-18 22:02 ` caroline dot rioux at ca dot ibm dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-02-18 21:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2009-02-18 21:45 -------
Fixed in 4.1.0 as mentioned already.  3.3.x is no longer maintained and any bug
that is reported against that old version is most likely not going to be ever
fixed.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.1.0


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


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

* [Bug libstdc++/39237] Overloaded Operator delete not called
  2009-02-18 21:38 [Bug libstdc++/39237] New: Overloaded Operator delete not called caroline dot rioux at ca dot ibm dot com
  2009-02-18 21:39 ` [Bug libstdc++/39237] " caroline dot rioux at ca dot ibm dot com
  2009-02-18 21:45 ` pinskia at gcc dot gnu dot org
@ 2009-02-18 22:02 ` caroline dot rioux at ca dot ibm dot com
  2009-02-18 22:06 ` pinskia at gcc dot gnu dot org
  2009-02-18 22:15 ` caroline dot rioux at ca dot ibm dot com
  4 siblings, 0 replies; 6+ messages in thread
From: caroline dot rioux at ca dot ibm dot com @ 2009-02-18 22:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from caroline dot rioux at ca dot ibm dot com  2009-02-18 22:02 -------
(In reply to comment #2)
> Fixed in 4.1.0 as mentioned already.  3.3.x is no longer maintained and any bug
> that is reported against that old version is most likely not going to be ever
> fixed.
> 

Ok thanks for your input. Was this explicitly fixed or a result of other
framework changes?  Is there any way a patch exists and could be applied?

I ask because it is unlikely we will move to gcc4 in the short term. Is
gcc3.4.x still supported? Because it also occurs there.


-- 


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


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

* [Bug libstdc++/39237] Overloaded Operator delete not called
  2009-02-18 21:38 [Bug libstdc++/39237] New: Overloaded Operator delete not called caroline dot rioux at ca dot ibm dot com
                   ` (2 preceding siblings ...)
  2009-02-18 22:02 ` caroline dot rioux at ca dot ibm dot com
@ 2009-02-18 22:06 ` pinskia at gcc dot gnu dot org
  2009-02-18 22:15 ` caroline dot rioux at ca dot ibm dot com
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-02-18 22:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2009-02-18 22:06 -------
(In reply to comment #3)
> Ok thanks for your input. Was this explicitly fixed or a result of other
> framework changes?  Is there any way a patch exists and could be applied?

Off hand I don't know.

> I ask because it is unlikely we will move to gcc4 in the short term. Is
> gcc3.4.x still supported? Because it also occurs there.

Nope, only currently 4.2 and above are being maintained.  Is there a reason why
you unlikely to move to 4.x in the short term? 


-- 


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


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

* [Bug libstdc++/39237] Overloaded Operator delete not called
  2009-02-18 21:38 [Bug libstdc++/39237] New: Overloaded Operator delete not called caroline dot rioux at ca dot ibm dot com
                   ` (3 preceding siblings ...)
  2009-02-18 22:06 ` pinskia at gcc dot gnu dot org
@ 2009-02-18 22:15 ` caroline dot rioux at ca dot ibm dot com
  4 siblings, 0 replies; 6+ messages in thread
From: caroline dot rioux at ca dot ibm dot com @ 2009-02-18 22:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from caroline dot rioux at ca dot ibm dot com  2009-02-18 22:15 -------
(In reply to comment #4)
> Nope, only currently 4.2 and above are being maintained.  Is there a reason why
> you unlikely to move to 4.x in the short term? 

We have a big code base and changing compilers is done seldom and very
carefully.  This bug will be one more reason to move though, so that's good :)

Is there any way you would know exactly what the bug is in this case? Is it a
leak, or that the memory is not free'd through delete, or that the overloaded
operator is not called when it should?  I searched the bug database but
couldn't find anything similar. 

Thanks again!


-- 


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


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

end of thread, other threads:[~2009-02-18 22:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-18 21:38 [Bug libstdc++/39237] New: Overloaded Operator delete not called caroline dot rioux at ca dot ibm dot com
2009-02-18 21:39 ` [Bug libstdc++/39237] " caroline dot rioux at ca dot ibm dot com
2009-02-18 21:45 ` pinskia at gcc dot gnu dot org
2009-02-18 22:02 ` caroline dot rioux at ca dot ibm dot com
2009-02-18 22:06 ` pinskia at gcc dot gnu dot org
2009-02-18 22:15 ` caroline dot rioux at ca dot ibm dot com

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).