belonxu / google-glog

Automatically exported from code.google.com/p/google-glog
Other
0 stars 0 forks source link

Apparent memory leak #156

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

$ cat test.cpp 
#include <gflags/gflags.h>
#include <glog/logging.h>

int main(int argc, char* argv[])
{
    google::InitGoogleLogging(argv[0]);

    google::ShutdownGoogleLogging();
    google::ShutDownCommandLineFlags();
}

$ g++  test.cpp -lglog -lgflags && valgrind --leak-check=full ./a.out

What is the expected output? What do you see instead?

I expect no leaks. Instead I see:

==13941== Memcheck, a memory error detector
==13941== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==13941== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==13941== Command: ./a.out
==13941== 
==13941== 
==13941== HEAP SUMMARY:
==13941==     in use at exit: 22 bytes in 1 blocks
==13941==   total heap usage: 168 allocs, 167 frees, 3,151 bytes allocated
==13941== 
==13941== 22 bytes in 1 blocks are possibly lost in loss record 1 of 1
==13941==    at 0x402BE94: operator new(unsigned int) (in 
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==13941==    by 0x43414F3: std::string::_Rep::_S_create(unsigned int, unsigned 
int, std::allocator<char> const&) (in 
/usr/lib/i386-linux-gnu/libstdc++.so.6.0.17)
==13941==    by 0x4343769: 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.17)
==13941==    by 0x4343F25: 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.17)
==13941==    by 0x406A3C5: ??? (in /usr/lib/i386-linux-gnu/libglog.so.0.0.0)
==13941==    by 0x406AABA: ??? (in /usr/lib/i386-linux-gnu/libglog.so.0.0.0)
==13941==    by 0x400F215: call_init (dl-init.c:84)
==13941==    by 0x400F2FB: _dl_init (dl-init.c:133)
==13941==    by 0x40011DE: ??? (in /lib/i386-linux-gnu/ld-2.17.so)
==13941== 
==13941== LEAK SUMMARY:
==13941==    definitely lost: 0 bytes in 0 blocks
==13941==    indirectly lost: 0 bytes in 0 blocks
==13941==      possibly lost: 22 bytes in 1 blocks
==13941==    still reachable: 0 bytes in 0 blocks
==13941==         suppressed: 0 bytes in 0 blocks
==13941== 
==13941== For counts of detected and suppressed errors, rerun with: -v
==13941== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

What version of the product are you using? On what operating system?

0.3.2, Ubuntu raring (but can reproduce with 0.3.3)

Please provide any additional information below.

It appears to be result from this flag in src/logging.cc:

GLOG_DEFINE_string(logmailer, "/bin/mail",
                   "Mailer used to send logging email");

replacing this with std::string FLAGS_logmailer("/bin/mail"); avoids the leak.

Original issue reported on code.google.com by a...@octopull.co.uk on 8 Apr 2013 at 10:35