mongocxx 驱动程序中可能未释放的内存

问题描述

如果我在 Linux 上使用 valgrind 运行我的应用程序,我会得到类似的堆栈跟踪,如下所示:

==20124== 524,288 bytes in 1 blocks are still reachable in loss record 1,065 of 1,065
==20124==    at 0x4C33D2F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20124==    by 0x77C999: bson_realloc (bson-memory.c:154)
==20124==    by 0x77CA04: bson_realloc_ctx (bson-memory.c:194)
==20124==    by 0x75E162: _mongoc_buffer_fill (mongoc-buffer.c:254)
==20124==    by 0x73324D: mongoc_stream_buffered_readv (mongoc-stream-buffered.c:240)
==20124==    by 0x733D09: mongoc_stream_readv (mongoc-stream.c:237)
==20124==    by 0x733E45: mongoc_stream_read (mongoc-stream.c:281)
==20124==    by 0x75DF38: _mongoc_buffer_append_from_stream (mongoc-buffer.c:200)
==20124==    by 0x6FB71C: mongoc_cluster_run_opmsg (mongoc-cluster.c:3468)
==20124==    by 0x6F5A7B: mongoc_cluster_run_command_monitored (mongoc-cluster.c:544)
==20124==    by 0x70A27A: _mongoc_cursor_run_command (mongoc-cursor.c:1052)
==20124==    by 0x70BAA1: _mongoc_cursor_response_refresh (mongoc-cursor.c:1673)
==20124==    by 0x70D09C: _prime (mongoc-cursor-find-cmd.c:36)
==20124==    by 0x70CEA4: _prime (mongoc-cursor-find.c:61)
==20124==    by 0x70A73E: _call_transition (mongoc-cursor.c:1204)
==20124==    by 0x70A962: mongoc_cursor_next (mongoc-cursor.c:1280)
==20124==    by 0x6528F0: mongocxx::v_noabi::cursor::iterator::operator++() (cursor.cpp:45)
==20124==    by 0x652C02: mongocxx::v_noabi::cursor::iterator::iterator(mongocxx::v_noabi::cursor*) (cursor.cpp:80)
==20124==    by 0x652B2D: mongocxx::v_noabi::cursor::begin() (cursor.cpp:67)
==20124==    ...

Valgrind 命令:

valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all --track-origins=yes --num-callers=200 ./

问题是它是在请求发出后才出现的,根据它,内存消耗不会减少到初始状态。 它来自的代码片段:

    mongocxx::cursor cursor = collection.find(document{} << "m" << matrixId << finalize);
    for(auto&& m : cursor) {

一些附加信息:

  • 我使用连接池并且使用acquire()方法获取客户端条目
  • 最初的实现为新线程上的每个请求提供服务,因此线程创建 - 退出保护请求执行。部署固定数量的线程池并由这些线程处理请求时出现的问题,因此当线程在处理请求后退出时,问题就消失了。

谁能帮帮我,出了什么问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)