valgrind报告gsoap中的内存泄漏

时间:2017-11-14 07:41:35

标签: memory-leaks valgrind gsoap

Valgrind正在检测Gsoap中的一些内存泄漏。这是一个非常基本的示例代码:

//file hr.cpp
#include "soapH.h"  
#include "ns1.nsmap"

int main()
{
    struct soap *soap_ = soap_new();

    soap_destroy(soap_);
    soap_end(soap_);
    //soap_done(soap_);
    soap_free(soap_);

    return 0;
}

要编译此代码,我使用:

g++ -D DEBUG -g -std=c++0x -o hr hr.cpp soapC.cpp stdsoap2.cpp

这些是Valgrind报告的内存泄漏:

==5290== HEAP SUMMARY:
==5290==     in use at exit: 72,800 bytes in 4 blocks
==5290==   total heap usage: 18 allocs, 14 frees, 244,486 bytes allocated
==5290==
==5290== 32 bytes in 1 blocks are definitely lost in loss record 1 of 4
==5290==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5290==    by 0x41D6FF: soap_track_malloc (stdsoap2.cpp:8952)
==5290==    by 0x421347: soap_set_logfile (stdsoap2.cpp:10022)
==5290==    by 0x421402: soap_set_test_logfile (stdsoap2.cpp:10062)
==5290==    by 0x422391: soap_init_REQUIRE_lib_v20851 (stdsoap2.cpp:10405)
==5290==    by 0x43DD31: soap::soap() (stdsoap2.cpp:20074)
==5290==    by 0x41AF2E: soap_new_REQUIRE_lib_v20851 (stdsoap2.cpp:8109)
==5290==    by 0x40238C: main (hr.cpp:6)
==5290==
==5290== 32 bytes in 1 blocks are definitely lost in loss record 2 of 4
==5290==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5290==    by 0x41D6FF: soap_track_malloc (stdsoap2.cpp:8952)
==5290==    by 0x421347: soap_set_logfile (stdsoap2.cpp:10022)
==5290==    by 0x4213DA: soap_set_sent_logfile (stdsoap2.cpp:10050)
==5290==    by 0x4223A2: soap_init_REQUIRE_lib_v20851 (stdsoap2.cpp:10406)
==5290==    by 0x43DD31: soap::soap() (stdsoap2.cpp:20074)
==5290==    by 0x41AF2E: soap_new_REQUIRE_lib_v20851 (stdsoap2.cpp:8109)
==5290==    by 0x40238C: main (hr.cpp:6)
==5290==
==5290== 32 bytes in 1 blocks are definitely lost in loss record 3 of 4
==5290==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5290==    by 0x41D6FF: soap_track_malloc (stdsoap2.cpp:8952)
==5290==    by 0x421347: soap_set_logfile (stdsoap2.cpp:10022)
==5290==    by 0x4213B2: soap_set_recv_logfile (stdsoap2.cpp:10038)
==5290==    by 0x4223B3: soap_init_REQUIRE_lib_v20851 (stdsoap2.cpp:10407)
==5290==    by 0x43DD31: soap::soap() (stdsoap2.cpp:20074)
==5290==    by 0x41AF2E: soap_new_REQUIRE_lib_v20851 (stdsoap2.cpp:8109)
==5290==    by 0x40238C: main (hr.cpp:6)
==5290==
==5290== LEAK SUMMARY:
==5290==    definitely lost: 96 bytes in 3 blocks
==5290==    indirectly lost: 0 bytes in 0 blocks
==5290==      possibly lost: 0 bytes in 0 blocks
==5290==    still reachable: 72,704 bytes in 1 blocks
==5290==         suppressed: 0 bytes in 0 blocks
==5290== Reachable blocks (those to which a pointer was found) are not shown.
==5290== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==5290==
==5290== For counts of detected and suppressed errors, rerun with: -v
==5290== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)

我做错了什么? 我错过了任何指示吗?我已阅读gsoap文档和互联网,但我没有找到任何内容。

非常感谢!

1 个答案:

答案 0 :(得分:1)

不要使用-DDEBUG编译代码以使用valgrind进行测试,因为它会激活gSOAP的内部内存泄漏检查程序。这可能会干扰valgrind。

修改

我使用最新版本2.8.61对此进行了验证,该版本显示DEBUG模式或其他情况下没有泄漏。我建议升级到gSOAP 2.8.61。