public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "antoinep92 at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/53169] New: Memory leak in std::vector<std::vector*> Date: Mon, 30 Apr 2012 14:06:00 -0000 [thread overview] Message-ID: <bug-53169-4@http.gcc.gnu.org/bugzilla/> (raw) 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.
next reply other threads:[~2012-04-30 14:06 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-04-30 14:06 antoinep92 at gmail dot com [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-53169-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).