We're updating the issue view to help you get more done. 

Memory leak in connection.cpp

Description

We are seeing increasing memory footpring of an application running fix8 as an engine.
After running the application in valgrind this is the result:
==11963== 41,970,200 bytes in 132,456 blocks are definitely lost in loss record 5,109 of 5,109
==11963== at 0x4C250B8: operator new(unsigned long) (vg_replace_malloc.c:333)
==11963== by 0x6BE86E8: allocate (new_allocator.h:104)
==11963== by 0x6BE86E8: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (basic_string.tcc:607)
==11963== by 0x6BE93CA: std::string::_Rep::_M_clone(std::allocator<char> const&, unsigned long) (basic_string.tcc:629)
==11963== by 0x6BE9473: std::string::reserve(unsigned long) (basic_string.tcc:510)
==11963== by 0x6BE96FE: std::string::append(char const*, unsigned long) (basic_string.tcc:308)
==11963== by 0x5A044DF: FIX8::FIXReader::read(std::string&) (connection.cpp:251)
==11963== by 0x5A04FA6: FIX8::FIXReader::execute(FIX8::f8_thread_cancellation_token&) (connection.cpp:102)
==11963== by 0x44E844: FIX8::AsyncSocket<std::string>::operator()() (connection.hpp:88)
==11963== by 0x455013: FIX8::f8_thread<FIX8::AsyncSocket<std::string> >::_helper::operator()() (thread.hpp:261)
==11963== by 0x453D1E: void FIX8::_f8_threadcore::_run<FIX8::f8_thread<FIX8::AsyncSocket<std::string> >::_helper>(void*) (thread.hpp:79)
==11963== by 0x6BE034F: execute_native_thread_routine (thread.cc:84)
==11963== by 0x4E3283C: start_thread (in /lib64/libpthread-2.5.so)

as you can see the valgrind points towards
connection.cpp:251 line:
to.append(msg_buf, mlen + _chksum_sz);

I analyzed the code and did not see any apparent issues,
the 'to' buffer is being cleared out with an assign invocation and then using an append call the buffer is being filled again.

Has anyone came across this or similar issue?

After further analysis and recompiling the code into gcc 5.3.0 i've found the following:
==13701== 69,417 bytes in 1,064 blocks are definitely lost in loss record 4,106 of 4,145
==13701== at 0x4C250B8: operator new(unsigned long) (vg_replace_malloc.c:333)
==13701== by 0x449F4D: void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>(char*, char*, std::forward_iterator_tag) (basic_string.tcc:223)
==13701== by 0x69F78FE: _M_construct_aux<char*> (basic_string.h:195)
==13701== by 0x69F78FE: _M_construct<char*> (basic_string.h:214)
==13701== by 0x69F78FE: std::_cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::_cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (basic_string.h:401)
==13701== by 0x432040: FIX8::Logger::LogElement::LogElement(FIX8::Logger::LogElement const&) (logger.hpp:203)
==13701== by 0x434255: FIX8::ff_unbounded_queue<FIX8::Logger::LogElement>::try_push(FIX8::Logger::LogElement const&) (ff_wrapper.hpp:62)
==13701== by 0x43229E: FIX8::Logger::enqueue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, FIX8::Logger::Level, char const*, unsigned int) (logger.hpp:297)

And:

==13701== by 0x69F78FE: std::_cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::_cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (basic_string.h:401)
==13701== by 0x432040: FIX8::Logger::LogElement::LogElement(FIX8::Logger::LogElement const&) (logger.hpp:203)
==13701== by 0x434255: FIX8::ff_unbounded_queue<FIX8::Logger::LogElement>::try_push(FIX8::Logger::LogElement const&) (ff_wrapper.hpp:62)
==13701== by 0x43229E: FIX8::Logger::enqueue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, FIX8::Logger::Level, char const*, unsigned int) (logger.hpp:297)
==13701== by 0x55D34A1: send (logger.hpp:307)
==13701== by 0x55D34A1: plog (session.hpp:697)
==13701== by 0x55D34A1: FIX8::Session::send_process(FIX8::Message*) (session.cpp:1024)
==13701== by 0x43E188: FIX8::FIXWriter::write(FIX8::Message*, bool) (connection.hpp:354)

It seems as if the logging is having some issues?

Environment

redhat 5, gcc 4.9.0

Status

Assignee

David Dight

Reporter

Aleksander Fular

Labels

None

Branch

dev

Products

Open Source

Time Tracking

5h

Components

Fix versions

Affects versions

1.3.4

Priority

Major