[Coin-discuss] potential memory leak in CoinMessageHandler used with Cbc

Kish Shen kisshen at cisco.com
Mon Feb 9 11:21:46 EST 2009


Hi,

I have been trying to track down this memory leak that shows up with 
valgrind, and I think it seems to happen when I allocate a 
CoinMessageHandler, as in the following:

CoinMessageHandler * coinMessageHandler = new CoinMessageHandler;
delete coinMessageHandler;

when this code is run, valgrind shows:

==4782== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 17 from 1)
==4782== malloc/free: in use at exit: 640 bytes in 1 blocks.
==4782== malloc/free: 5 allocs, 4 frees, 3,712 bytes allocated.
==4782== For counts of detected errors, rerun with: -v
==4782== searching for pointers to 1 not-freed blocks.
==4782== checked 123,620 bytes.
==4782==
==4782== 640 bytes in 1 blocks are still reachable in loss record 1 of 1
==4782==    at 0x401CA9F: operator new(unsigned) (vg_replace_malloc.c:163)
==4782==    by 0x40BE008: std::__default_alloc_template<true, 
0>::_S_chunk_alloc(unsigned, int&) (in /usr/lib/libstdc++.so.5.0.7)
==4782==    by 0x40BE0FC: std::__default_alloc_template<true, 
0>::_S_refill(unsigned) (in /usr/lib/libstdc++.so.5.0.7)
==4782==    by 0x40BE416: std::__default_alloc_template<true, 
0>::allocate(unsigned) (in /usr/lib/libstdc++.so.5.0.7)
==4782==    by 0x40C0C6D: std::string::_Rep::_S_create(unsigned, 
std::allocator<char> const&) (in /usr/lib/libstdc++.so.5.0.7)
==4782==    by 0x40C26F4: std::string::_M_mutate(unsigned, unsigned, 
unsigned) (in /usr/lib/libstdc++.so.5.0.7)
==4782==    by 0x40C2868: std::string& std::string::_M_replace_safe<char 
const*>(__gnu_cxx::__normal_iterator<char*, std::string>, 
__gnu_cxx::__normal_iterator<char*, std::string>, char const*, char 
const*) (in /usr/lib/libstdc++.so.5.0.7)
==4782==    by 0x40C2963: std::string::assign(char const*, unsigned) (in 
/usr/lib/libstdc++.so.5.0.7)
==4782==    by 0x40C2AD4: std::string::operator=(char const*) (in 
/usr/lib/libstdc++.so.5.0.7)
==4782==    by 0x830EEC0: CoinMessageHandler::CoinMessageHandler() 
(CoinMessageHandler.cpp:440)
==4782==    by 0x804E551: coin_create_prob (coinplex.cpp:1430)
==4782==    by 0x8383780: step_00 (bug.c:6)
==4782==
==4782== LEAK SUMMARY:
==4782==    definitely lost: 0 bytes in 0 blocks.
==4782==      possibly lost: 0 bytes in 0 blocks.
==4782==    still reachable: 640 bytes in 1 blocks.
==4782==         suppressed: 0 bytes in 0 blocks.

coin_create_prob is where the above code is define. It is the only call 
made.

The above is a much simplified version of the calls I made, and the leak 
shows up as `still reachable'. In the actual code I use, this 640 bytes 
shows up as definitely lost.

I am using the trunk branch of Cbc that I downloaded on 14 Nov 2008.
Line 440 of CoinMessageHandler.cpp is

   source_="Unk";

in CoinMessageHandler::CoinMessageHandler()

Any suggestions on how I could prevent this leak with be most welcomed!

Cheers,

Kish

-- 
This e-mail may contain confidential and privileged material for the
sole use of the intended recipient. Any review, use, distribution or
disclosure by others is strictly prohibited. If you are not the intended
recipient (or authorized to receive for the recipient), please contact
the sender by reply e-mail and delete all copies of this message.
Cisco Systems Limited (Company Number: 02558939), is registered in
England and Wales with its registered office at 1 Callaghan Square,
Cardiff, South Glamorgan CF10 5BT.




More information about the Coin-discuss mailing list