内存泄漏与mongocxx :: instance inst {};

时间:2017-10-17 12:44:57

标签: c++ linux mongodb mongo-cxx-driver

Valgrind给我一个mongocxx :: instance inst {}的still reachable记录;

==3014== 16,384 bytes in 1 blocks are still reachable in loss record 609 of 609
==3014==    at 0x5374C20: realloc (vg_replace_malloc.c:662)
==3014==    by 0x396046ACCE: CRYPTO_realloc (in /usr/lib64/libcrypto.so.1.0.1e)
==3014==    by 0x39604E604D: lh_insert (in /usr/lib64/libcrypto.so.1.0.1e)
==3014==    by 0x39604E87C8: ??? (in /usr/lib64/libcrypto.so.1.0.1e)
==3014==    by 0x39604E814B: ??? (in /usr/lib64/libcrypto.so.1.0.1e)
==3014==    by 0x396054C2FD: ERR_load_CMS_strings (in /usr/lib64/libcrypto.so.1.0.1e)
==3014==    by 0x3963045A38: SSL_load_error_strings (in /usr/lib64/libssl.so.1.0.1e)
==3014==    by 0x62BD653: ??? (in /usr/lib64/libmongoc-1.0.so.0.0.0)
==3014==    by 0x62A2278: ??? (in /usr/lib64/libmongoc-1.0.so.0.0.0)
==3014==    by 0x395BC0CE02: pthread_once (in /lib64/libpthread-2.12.so)
==3014==    by 0x55ADDE5: std::unique_ptr<mongocxx::v_noabi::instance::impl, std::default_delete<mongocxx::v_noabi::instance::impl> > core::v1::make_unique<mongocxx::v_noabi::instance::impl, void, std::unique_ptr<mongocxx::v_noabi::logger, std::default_delete<mongocxx::v_noabi::logger> > >(std::unique_ptr<mongocxx::v_noabi::logger, std::default_delete<mongocxx::v_noabi::logger> >&&) (in /usr/lib64/libmongocxx.so.3.0.3)
==3014==    by 0x55ADAEE: mongocxx::v_noabi::instance::instance(std::unique_ptr<mongocxx::v_noabi::logger, std::default_delete<mongocxx::v_noabi::logger> >) (in /usr/lib64/libmongocxx.so.3.0.3)
==3014==    by 0x55ADCF4: mongocxx::v_noabi::instance::instance() (in /usr/lib64/libmongocxx.so.3.0.3)
==3014==    by 0x4F6188: main (main.c:280)

如何摆脱这种情况。 我在fork之后但在创建任何线程之前声明了实例。

1 个答案:

答案 0 :(得分:0)

我的建议是在验证以下内容后为此写一个抑制:

  • 您是否确认mongocxx::instance对象的dtor正在执行?
  • 您是否确认该对象的dtor实际上正在调用mongoc_cleanup

如果这两个都是真的,那么你的下一个问题是询问libcrypto是否真的在任何路径下释放了这个分配的数据。如果答案是肯定的,那么你的下一个问题是问为什么它没有被调用。如果答案是“否”,那么你应该写一个抑制。

在这里编写抑制可能是合适的,因为这几乎肯定是一次性分配,因此不依赖于每个操作上下文,这将导致无限的内存增长。

另外,请注意内存实际上没有泄露 - 它仍然可以访问。