Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#9108 closed Bugs (fixed)

flat_multimap leaks on insert(Iterator, Iterator)

Reported by: adam.m.baxter@… Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: container
Version: Boost 1.54.0 Severity: Problem
Keywords: Cc:



#include <iostream> #include <boost/container/flat_map.hpp>

typedef boost::container::flat_multimap<int,int> IntMap?;

class MapTest? { public:

MapTest?() {} MapTest?(IntMap? const &map) :

_map(map) { _map.insert(map.begin(), map.end());

} IntMap? const& getMap() {return _map; }


IntMap? _map;


int main(int argc, char *argv[]) {

using std::cout; using std::endl;

IntMap? iMap; for(int i = 0; i < 1000; i++) {

iMap.emplace(i, i);


MapTest? map(iMap); for(auto const &kvPair : map.getMap()) {

cout << kvPair.first << " : " << kvPair.second << endl;

} return 0;


Valgrind Output:

==15820== ==15820== HEAP SUMMARY: ==15820== in use at exit: 8,000 bytes in 1 blocks ==15820== total heap usage: 20 allocs, 19 frees, 49,624 bytes allocated ==15820== ==15820== 8,000 bytes in 1 blocks are definitely lost in loss record 1 of 1 ==15820== at 0x4A068F3: operator new(unsigned long) (in /usr/lib64/valgrind/ ==15820== by 0x4016EF: MapTest::MapTest?(boost::container::flat_multimap<int, int, std::less<int>, std::allocator<std::pair<int, int> > > const&) (in /home/abaxter/Projects/Du/apollo-build/bin/sandbox) ==15820== by 0x4013B9: main (in /home/abaxter/Projects/Du/apollo-build/bin/sandbox) ==15820== ==15820== LEAK SUMMARY: ==15820== definitely lost: 8,000 bytes in 1 blocks ==15820== indirectly lost: 0 bytes in 0 blocks ==15820== possibly lost: 0 bytes in 0 blocks ==15820== still reachable: 0 bytes in 0 blocks ==15820== suppressed: 0 bytes in 0 blocks ==15820==

Attachments (2)

sandbox.cpp (659 bytes) - added by adam.m.baxter@… 4 years ago.
Reproducer program
boost_error.txt (1.1 KB) - added by Adam Baxter <adam.m.baxter@…> 4 years ago.
Valgrind error message

Download all attachments as: .zip

Change History (8)

Changed 4 years ago by adam.m.baxter@…

Attachment: sandbox.cpp added

Reproducer program

Changed 4 years ago by Adam Baxter <adam.m.baxter@…>

Attachment: boost_error.txt added

Valgrind error message

comment:1 Changed 4 years ago by Adam Baxter <adam.m.baxter@…>

Apparently the copy got butchered as I forgot to do any formatting. I've attached the sandbox program and valgrind message to this ticket.

While the program does a nonsensical thing, it was the only way I could get the bug to reproduce in something so simple

comment:2 Changed 4 years ago by Adam Baxter <adam.m.baxter@…>

Summary: flat_map leaks on insert(Iterator, Iterator)flat_multimap leaks on insert(Iterator, Iterator)

comment:3 Changed 4 years ago by Adam Baxter <adam.m.baxter@…>

I have proof that a similar thing happens with flat maps, but I'm unable to successfully create a reproducer at this point.

comment:4 Changed 4 years ago by Ion Gaztañaga

I just noticed that this is not a flat_xxx problem but vector's problem. The reserve() function leaks memory.

comment:5 Changed 4 years ago by Ion Gaztañaga

Resolution: fixed
Status: newclosed

(In [85658]) Fixes #9108

comment:6 Changed 4 years ago by Adam Baxter <adam.m.baxter@…>


Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Ion Gaztañaga.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.