记忆力不断增长

时间:2014-11-05 22:54:43

标签: c++ memory-leaks poco-libraries

我很确定图书馆的这个Poco部分没有泄漏,但我也无法弄清楚为什么内存不断增加。

如果我让这个程序运行半分钟,ram内存增加超过10MB,从不到一个开始。

#include "Poco/Net/SSLManager.h"
    int main(int argc, const char * argv[])
    {
        int counter = 0;
        while(counter < 1000000)
        {
            Poco::Net::Context::Ptr context = new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, "", "", "", Poco::Net::Context::VERIFY_NONE, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
            counter++;
        }

        return 0;
    }

我设置了一个断点来查看该对象是否被删除而且确实如此;

inline void RefCountedObject::release() const
{
    if (--_counter == 0) delete this;
}

上面的代码来自类Foundation_API RefCountedObject ,它由上下文使用。

我花了差不多两天的时间试图理解为什么内存不断增加。 用Valgrind进行测试,它说它确实泄漏了内存,但没有人在互联网上提到这一点。

编译并运行在Ubuntu和Mac OS x上,同样的问题。

谢谢。

稍后编辑: 通过在mac os x上运行 valgrind --leak-check = yes ./exec ,下面是输出:

==808== Memcheck, a memory error detector
==808== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==808== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
==808== Command: ./exec
==808== 
--808-- ./exec:
--808-- dSYM directory is missing; consider using --dsymutil=yes
--808-- /Users/myusername/bla/local/blaStream/blaStream/Libraries/libjson_linux-gcc-4.2.1_libmt.dylib:
--808-- dSYM directory is missing; consider using --dsymutil=yes
--808-- /Users/myusername/bla/local/blaStream/blaStream/Libraries/libboost_system-mt.dylib:
--808-- dSYM directory is missing; consider using --dsymutil=yes
--808-- /Users/myusername/bla/local/blaStream/blaStream/Libraries/libboost_thread-mt.dylib:
--808-- dSYM directory is missing; consider using --dsymutil=yes
UNKNOWN __pthread_sigmask is unsupported. This warning will not be repeated.
==808== 
==808== HEAP SUMMARY:
==808==     in use at exit: 72,981 bytes in 1,029 blocks
==808==   total heap usage: 305,673 allocs, 304,644 frees, 11,304,653 bytes allocated
==808== 
==808== 72 (32 direct, 40 indirect) bytes in 1 blocks are definitely lost in loss record 73 of 131
==808==    at 0x47F1: malloc (vg_replace_malloc.c:300)
==808==    by 0x8294F3: CRYPTO_malloc (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x80BEDB: sk_new_null (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x81EE87: engine_cleanup_add_last (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x7FFD4E: ENGINE_add (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x87FF55: ENGINE_load_dynamic (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x83180C: OPENSSL_config (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x1152669: Poco::Crypto::OpenSSLInitializer::initialize() (in /usr/local/Cellar/poco/1.4.6p4-all/lib/libPocoCrypto.16.dylib)
==808==    by 0xFC6DE: Poco::Net::Context::Context(Poco::Net::Context::Usage, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Poco::Net::Context::VerificationMode, int, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) (in /usr/local/Cellar/poco/1.4.6p4-all/lib/libPocoNetSSL.16.dylib)
==808==    by 0xFC67F: Poco::Net::Context::Context(Poco::Net::Context::Usage, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Poco::Net::Context::VerificationMode, int, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) (in /usr/local/Cellar/poco/1.4.6p4-all/lib/libPocoNetSSL.16.dylib)
==808==    by 0x100027ADB: main (in ./exec)
==808== 
==808== 904 (176 direct, 728 indirect) bytes in 1 blocks are definitely lost in loss record 100 of 131
==808==    at 0x47F1: malloc (vg_replace_malloc.c:300)
==808==    by 0x8294F3: CRYPTO_malloc (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x825CE5: lh_new (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x83AAC2: def_get_class (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x83A4E8: int_new_ex_data (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x81EBFE: ENGINE_new (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x87FEBA: ENGINE_load_dynamic (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x83180C: OPENSSL_config (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x1152669: Poco::Crypto::OpenSSLInitializer::initialize() (in /usr/local/Cellar/poco/1.4.6p4-all/lib/libPocoCrypto.16.dylib)
==808==    by 0xFC6DE: Poco::Net::Context::Context(Poco::Net::Context::Usage, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Poco::Net::Context::VerificationMode, int, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) (in /usr/local/Cellar/poco/1.4.6p4-all/lib/libPocoNetSSL.16.dylib)
==808==    by 0xFC67F: Poco::Net::Context::Context(Poco::Net::Context::Usage, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Poco::Net::Context::VerificationMode, int, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) (in /usr/local/Cellar/poco/1.4.6p4-all/lib/libPocoNetSSL.16.dylib)
==808==    by 0x100027ADB: main (in ./exec)
==808== 
==808== 1,536 (176 direct, 1,360 indirect) bytes in 1 blocks are definitely lost in loss record 119 of 131
==808==    at 0x47F1: malloc (vg_replace_malloc.c:300)
==808==    by 0x8294F3: CRYPTO_malloc (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x825CE5: lh_new (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x87E33D: int_thread_get (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x87E54A: int_thread_set_item (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x87DE34: ERR_get_state (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x85DF4B: ERR_clear_error (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x83180C: OPENSSL_config (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x1152669: Poco::Crypto::OpenSSLInitializer::initialize() (in /usr/local/Cellar/poco/1.4.6p4-all/lib/libPocoCrypto.16.dylib)
==808==    by 0xFC6DE: Poco::Net::Context::Context(Poco::Net::Context::Usage, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Poco::Net::Context::VerificationMode, int, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) (in /usr/local/Cellar/poco/1.4.6p4-all/lib/libPocoNetSSL.16.dylib)
==808==    by 0xFC67F: Poco::Net::Context::Context(Poco::Net::Context::Usage, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Poco::Net::Context::VerificationMode, int, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) (in /usr/local/Cellar/poco/1.4.6p4-all/lib/libPocoNetSSL.16.dylib)
==808==    by 0x100027ADB: main (in ./exec)
==808== 
==808== 2,048 bytes in 1 blocks are definitely lost in loss record 120 of 131
==808==    at 0x51C7: calloc (vg_replace_malloc.c:627)
==808==    by 0xC9100A: strerror (in /usr/lib/system/libsystem_c.dylib)
==808==    by 0x853C87: ERR_load_ERR_strings (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x872388: ERR_load_crypto_strings (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x7C5DC8: SSL_load_error_strings (in /usr/lib/libssl.0.9.8.dylib)
==808==    by 0x1152673: Poco::Crypto::OpenSSLInitializer::initialize() (in /usr/local/Cellar/poco/1.4.6p4-all/lib/libPocoCrypto.16.dylib)
==808==    by 0xFC6DE: Poco::Net::Context::Context(Poco::Net::Context::Usage, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Poco::Net::Context::VerificationMode, int, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) (in /usr/local/Cellar/poco/1.4.6p4-all/lib/libPocoNetSSL.16.dylib)
==808==    by 0xFC67F: Poco::Net::Context::Context(Poco::Net::Context::Usage, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Poco::Net::Context::VerificationMode, int, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) (in /usr/local/Cellar/poco/1.4.6p4-all/lib/libPocoNetSSL.16.dylib)
==808==    by 0x100027ADB: main (in ./exec)
==808== 
==808== 21,728 (32 direct, 21,696 indirect) bytes in 1 blocks are definitely lost in loss record 131 of 131
==808==    at 0x47F1: malloc (vg_replace_malloc.c:300)
==808==    by 0x8294F3: CRYPTO_malloc (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x80BEDB: sk_new_null (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x867092: CONF_module_add (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x82C5C8: OPENSSL_load_builtin_modules (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x831807: OPENSSL_config (in /usr/lib/libcrypto.0.9.8.dylib)
==808==    by 0x1152669: Poco::Crypto::OpenSSLInitializer::initialize() (in /usr/local/Cellar/poco/1.4.6p4-all/lib/libPocoCrypto.16.dylib)
==808==    by 0xFC6DE: Poco::Net::Context::Context(Poco::Net::Context::Usage, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Poco::Net::Context::VerificationMode, int, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) (in /usr/local/Cellar/poco/1.4.6p4-all/lib/libPocoNetSSL.16.dylib)
==808==    by 0xFC67F: Poco::Net::Context::Context(Poco::Net::Context::Usage, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Poco::Net::Context::VerificationMode, int, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) (in /usr/local/Cellar/poco/1.4.6p4-all/lib/libPocoNetSSL.16.dylib)
==808==    by 0x100027ADB: main (in ./exec)
==808== 
==808== LEAK SUMMARY:
==808==    definitely lost: 2,464 bytes in 5 blocks
==808==    indirectly lost: 33,184 bytes in 639 blocks
==808==      possibly lost: 0 bytes in 0 blocks
==808==    still reachable: 264 bytes in 3 blocks
==808==         suppressed: 37,069 bytes in 382 blocks
==808== Reachable blocks (those to which a pointer was found) are not shown.

1 个答案:

答案 0 :(得分:1)

可能由于this issue; fix将在1.6.0