c - valgrind - 使用 C api 连接到 mongodb 而不会导致 SIGSEGV

标签 c mongodb valgrind mongo-c-driver

我正在尝试使用 C-API 连接到 mongodb,我的代码似乎运行良好。然而,仔细检查 Valgrind 提示我在做非法的事情。

我的程序接受参数 -h <hostname> , 然后将此字符串转换为 mongodb_uri然后尝试连接到 mongodb:

*client_p = mongoc_client_new(host);

if (!*client_p) {
   log_die("Failed to parse URI!");
} 

我的程序按预期运行,但是当我用 valgrind 检查它时,它调用了 mongoc_client_new导致 SIGSEGV:

==28775== Memcheck, a memory error detector
==28775== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==28775== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==28775== Command: ./coll2tde -h mongodb://localhost -d test -c testq
==28775== 
aTrying to connect to mongodb://localhost
2014/12/25 22:22:21.0255: [28775]:    DEBUG:      cluster: Client initialized in direct mode.
==28775== Jump to the invalid address stated on the next line
==28775==    at 0xFFFFFFFFFF600800: ???
==28775==    by 0x402722: get_cursor (mongo.c:26)
==28775==    by 0x402330: main (coll2tde.c:120)
==28775==  Address 0xffffffffff600800 is not stack'd, malloc'd or (recently) free'd
==28775== 
==28775== 
==28775== Process terminating with default action of signal 11 (SIGSEGV)
==28775==  Bad permissions for mapped region at address 0xFFFFFFFFFF600800
==28775==    at 0xFFFFFFFFFF600800: ???
==28775==    by 0x402722: get_cursor (mongo.c:26)
==28775==    by 0x402330: main (coll2tde.c:120)
==28775== 
==28775== HEAP SUMMARY:
==28775==     in use at exit: 114,751 bytes in 3,194 blocks
==28775==   total heap usage: 3,615 allocs, 421 frees, 177,386 bytes allocated
==28775== 
==28775== LEAK SUMMARY:
==28775==    definitely lost: 6,784 bytes in 1 blocks
==28775==    indirectly lost: 2,968 bytes in 11 blocks
==28775==      possibly lost: 1,462 bytes in 19 blocks
==28775==    still reachable: 103,537 bytes in 3,163 blocks
==28775==         suppressed: 0 bytes in 0 blocks
==28775== Rerun with --leak-check=full to see details of leaked memory
==28775== 
==28775== For counts of detected and suppressed errors, rerun with: -v
==28775== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 8 from 6)
Killed

一开始我以为是我的代码有问题,后来我从 mogoc_client documentation编译了例子并看到相同的行为。我想知道这是一个错误还是可以安全地忽略它。

最佳答案

在花了几个小时试图解决这个问题后,it turns out this is a problem with older versions of Valgrind (在 Debian Wheezy 上为 3.7)。我从上游来源编译了 Valgrind 3.10.1 版本,这个问题消失了。

关于c - valgrind - 使用 C api 连接到 mongodb 而不会导致 SIGSEGV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27647779/

相关文章:

c++ - 在 char* 中存储整数

c - 这段代码是正确的还是我必须在使它等于 name2 之前分配 name

arrays - 更新 mongodb 中的嵌套数组

javascript - MongoDB - MongoError : connect ECONNREFUSED

c++ - Callgrind:分析我的代码的特定部分

c - 为什么我的程序有内存泄漏检查错误?

c - 未映射的符号

c - 使用 radio.write() 发送小数;与阿杜诺

mongodb - 往返Mongo的Grails日期转换

c++ - 如何解释 Valgrind 输出