public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/53169] New: Memory leak in std::vector<std::vector*>
@ 2012-04-30 14:06 antoinep92 at gmail dot com
  2012-04-30 14:28 ` [Bug libstdc++/53169] " redi at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: antoinep92 at gmail dot com @ 2012-04-30 14:06 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53169
           Summary: Memory leak in std::vector<std::vector*>
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: antoinep92@gmail.com


Created attachment 27268
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27268
Test case: 500Mb used after memory neutral function returns!

The attached source is a minimal test case, implementing a sparse array of
std::vectors in class Collection, and test() demonstrates its use in a memory
neutral way (all allocated objects are freed).

When compiled on x86-64 linux with gcc 4.6.1, gcc 4.7.1 and clang 3.0 (using
GNU libstdc++), tools such as top show that memory increases when running
test(), but does not not decrease after the function exits: 500Mb are lost in
this test case. Just increase to loop count and make that 4Gb if you wish: the
amount of  leaked memory don't seem to be bounded.
`valgrind --leak-check=full ./a.out` reports there is not a single byte leaked,
which I double checked with the heap profiler from google perf tools.

The memory is reserved by libstdc++ and unavailable to other processes or
subsequent malloc/frees within the same program. Subsequent C++ STL allocations
(e.g. resizing a big vector) on the other hand don't register on process memory
and seem to ruse the reserved buffers; sometimes they even trigger deallocation
of the "leaked" memory.
For example when running test() multiple times, the bug only occurs on the
first call. Subsequent calls free memory when done. I guess the reserved memory
is accounted for within libstdc++ internals, and deallocated on finalization
which is why valgrind can't see it.

My application is a sequence of memory intensive operations, and this bug
prevents memory from being freed between steps, and the system quickly runs out
of memory.

Thanks a lot!

*** Note: As this is quite time-critical for me, if someone points me in the
right direction (files, classes involved) I can try to investigate this and
send back a patch.


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

end of thread, other threads:[~2012-04-30 15:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-30 14:06 [Bug libstdc++/53169] New: Memory leak in std::vector<std::vector*> antoinep92 at gmail dot com
2012-04-30 14:28 ` [Bug libstdc++/53169] " redi at gcc dot gnu.org
2012-04-30 14:59 ` redi at gcc dot gnu.org
2012-04-30 15:13 ` redi at gcc dot gnu.org
2012-04-30 15:16 ` redi at gcc dot gnu.org
2012-04-30 15:27 ` antoinep92 at gmail dot com
2012-04-30 15:31 ` antoinep92 at gmail dot com
2012-04-30 15:52 ` redi at gcc dot gnu.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).