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)
我如何摆脱这一点。
我在派生之后但在创建任何线程之前声明实例。
最佳答案
我的建议是,在验证以下内容之后,您为此写一个抑制符:
mongocxx::instance
对象的dtor正在执行? mongoc_cleanup
? 如果这两个都是正确的,那么您的下一个问题是询问libcrypto是否实际上在任何路径下都释放了分配的数据。如果答案是肯定的,那么您的下一个问题是问为什么它没有被调用。如果答案是“否”,那么您应该写一个抑制词。
在这里写一个抑制可能是适当的,因为这几乎可以肯定是一次分配,因此与每个操作上下文无关,后者会导致无限的内存增长。
此外,请注意,内存实际上并未泄漏-仍然可以访问。
关于c++ - mongocxx::instance inst {}导致内存泄漏,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46790473/