Search code examples
c++memory-leakslog4cxx

Does log4cxx::Level::getError() leak memory?


I use the log4cxx logging library in a project and Valgrind Memory Analyzer (in Qt Creator) to check for memory leaks.

It appears to me that the log4cxx::Level::getError() and log4cxx::Level::getFatal() leak 18 bytes of memory.

Here is the relevant part of the Valgrind dump:

18 bytes in 1 blocks are possibly lost in loss record 157 of 409 in OLogger::getLogLevel(char const*) in XXX/Infrastructure/Logging/OLogger.cpp:51
  1: operator new(unsigned int) in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so
  2: std::string::_Rep::_S_create(unsigned int, unsigned int, std::allocator<char> const&) in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.19
  3: char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.19
  4: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.19
  5: log4cxx::Level::getError() in /usr/lib/liblog4cxx.so.10.0.0
  6: OLogger::getLogLevel(char const*) in XXX/Infrastructure/Logging/OLogger.cpp:51

Now the question is if the library intentionally leaks memory in a view places. VLD, for example, had problems in the past with statically allocated memory. Maybe the logging system wants to stay alive as long as possible to report errors leading to memory leaks. That's just my speculations...

Can anyone verify that leak? Is it there by design? What do I have to do to remove it, if possible?

Thank you :-)


Solution

  • According to a short discussion at apache.org the leak is there in my current version (see log in my question).

    The leak needs further investigation, for example, in the development branch of log4cxx.

    I post this as answer because I know now that the leak does not stem from me.