2017-10-17 64 views
1

Valgrind給我一個still reachable記錄與mongocxx ::實例inst {};使用mongocxx :: inst {}執行內存泄漏;

==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之後但在創建任何線程之前聲明實例。

回答

0

我的建議是,你寫一個抑制這一點,覈實後執行以下操作:

  • 是否已確認您mongocxx::instance對象的析構函數正在執行?
  • 您是否已覈實該物體的實際上是否調用了mongoc_cleanup

如果這兩個都是真的,那麼你的下一個問題是詢問libcrypto是否真的在任何路徑下釋放這個分配的數據。如果答案是肯定的,那麼你的下一個問題就是問爲什麼它沒有被調用。如果答案是「否」,那麼你應該寫一個抑制。

寫一個抑制可能適合這裏,因爲這幾乎可以肯定是一次性分配,因此不會綁定到每個操作上下文,這會導致無限的內存增長。

此外,請注意內存實際上沒有泄漏 - 它仍然可以訪問。