C++ Valgrind在使用API时报告内存泄漏

C++ Valgrind在使用API时报告内存泄漏,c++,valgrind,C++,Valgrind,我正在用dyninstapi构建一个应用程序,通过一个简单的helloworld应用程序,会有很多内存泄漏。Dyninst正在部分管理自己的内存,我很好奇Valgrind是否会报告内存“泄漏” 我使用C++,还有一个不太舒服的100%,所以如果我忘了包含任何有帮助的信息,请说。 谢谢 以下是Hello World应用程序: #include "BPatch.h" int main(int argc, char** argv) { BPatch bpatch; } Valgrind输出

我正在用dyninstapi构建一个应用程序,通过一个简单的helloworld应用程序,会有很多内存泄漏。Dyninst正在部分管理自己的内存,我很好奇Valgrind是否会报告内存“泄漏”

<>我使用C++,还有一个不太舒服的100%,所以如果我忘了包含任何有帮助的信息,请说。 谢谢


以下是Hello World应用程序:

#include "BPatch.h"
int main(int argc, char** argv) {
  BPatch bpatch;
}

Valgrind输出:

==10307== Memcheck, a memory error detector.
==10307== Copyright (C) 2002-2008, and GNU GPL'd, by Julian Seward et al.
==10307== Using LibVEX rev 1884, a library for dynamic binary translation.
==10307== Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP.
==10307== Using valgrind-3.4.1-Debian, a dynamic binary instrumentation framework.
==10307== Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward et al.
==10307== For more details, rerun with: -v
==10307== 
==10307== 
==10307== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 31 from 1)
==10307== malloc/free: in use at exit: 16,021 bytes in 422 blocks.
==10307== malloc/free: 2,198 allocs, 1,776 frees, 74,304 bytes allocated.
==10307== For counts of detected errors, rerun with: -v
==10307== searching for pointers to 422 not-freed blocks.
==10307== checked 8,642,848 bytes.
==10307== 
==10307== 44 (12 direct, 32 indirect) bytes in 1 blocks are definitely lost in loss record 51 of 95
==10307==    at 0x40269EE: operator new(unsigned int) (vg_replace_malloc.c:224)
==10307==    by 0x46505EF: Dyninst::SymtabAPI::typeCollection::getAllTypes() (Collections.C:515)
==10307==    by 0x46223F6: Dyninst::SymtabAPI::Symtab::getAllstdTypes() (Symtab.C:2182)
==10307==    by 0x435E510: BPatch::BPatch() (in ~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so)
==10307==    by 0x804914B: main (mutator.c:14)
==10307== 
==10307== 
==10307== 20 bytes in 1 blocks are definitely lost in loss record 52 of 95
==10307==    at 0x40269EE: operator new(unsigned int) (vg_replace_malloc.c:224)
==10307==    by 0x438C3C4: BPatch_type::BPatch_type(Dyninst::SymtabAPI::Type*) (in ~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so)
==10307==    by 0x435E54F: BPatch::BPatch() (in ~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so)
==10307==    by 0x804914B: main (mutator.c:14)
==10307== 
==10307== 
==10307== 266 (72 direct, 194 indirect) bytes in 2 blocks are definitely lost in loss record 69 of 95
==10307==    at 0x40269EE: operator new(unsigned int) (vg_replace_malloc.c:224)
==10307==    by 0x438B6D7: BPatch_type::BPatch_type(char const*, int, BPatch_dataClass) (in ~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so)
==10307==    by 0x438BCAA: BPatch_type::createFake(char const*) (in ~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so)
==10307==    by 0x435E4DB: BPatch::BPatch() (in ~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so)
==10307==    by 0x804914B: main (mutator.c:14)
==10307== 
==10307== 
==10307== 1,412 bytes in 60 blocks are possibly lost in loss record 82 of 95
==10307==    at 0x40269EE: operator new(unsigned int) (vg_replace_malloc.c:224)
==10307==    by 0x4817AD3: std::string::_Rep::_S_create(unsigned int, unsigned int, std::allocator<char> const&) (in /usr/lib/libstdc++.so.6.0.10)
==10307==    by 0x4818734: (within /usr/lib/libstdc++.so.6.0.10)
==10307==    by 0x48188A5: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) (in /usr/lib/libstdc++.so.6.0.10)
==10307==    by 0x4665707: global constructors keyed to annotations.C (annotations.C:38)
==10307==    by 0x4666E3C: (within ~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libsymtabAPI.so)
==10307==    by 0x45A85AF: (within ~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libsymtabAPI.so)
==10307==    by 0x400E343: (within /lib/ld-2.9.so)
==10307==    by 0x400E473: (within /lib/ld-2.9.so)
==10307==    by 0x400084E: (within /lib/ld-2.9.so)
==10307== 
==10307== 
==10307== 3,657 (72 direct, 3,585 indirect) bytes in 1 blocks are definitely lost in loss record 84 of 95
==10307==    at 0x40269EE: operator new(unsigned int) (vg_replace_malloc.c:224)
==10307==    by 0x435E583: BPatch::BPatch() (in ~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so)
==10307==    by 0x804914B: main (mutator.c:14)
==10307== 
==10307== 
==10307== 268 (12 direct, 256 indirect) bytes in 1 blocks are definitely lost in loss record 85 of 95
==10307==    at 0x40269EE: operator new(unsigned int) (vg_replace_malloc.c:224)
==10307==    by 0x465072F: Dyninst::SymtabAPI::builtInTypeCollection::getAllBuiltInTypes() (Collections.C:673)
==10307==    by 0x46223C6: Dyninst::SymtabAPI::Symtab::getAllbuiltInTypes() (Symtab.C:2188)
==10307==    by 0x435E598: BPatch::BPatch() (in ~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so)
==10307==    by 0x804914B: main (mutator.c:14)
==10307== 
==10307== 
==10307== 144 bytes in 1 blocks are possibly lost in loss record 91 of 95
==10307==    at 0x4025092: calloc (vg_replace_malloc.c:397)
==10307==    by 0x401128B: _dl_allocate_tls (in /lib/ld-2.9.so)
==10307==    by 0x4A0F672: pthread_create@@GLIBC_2.1 (in /lib/tls/i686/cmov/libpthread-2.9.so)
==10307==    by 0x441B852: InternalThread::createThread() (in ~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so)
==10307==    by 0x44543B5: BPatch_asyncEventHandler::initialize() (in ~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so)
==10307==    by 0x435E62A: BPatch::BPatch() (in ~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so)
==10307==    by 0x804914B: main (mutator.c:14)
==10307== 
==10307== LEAK SUMMARY:
==10307==    definitely lost: 188 bytes in 6 blocks.
==10307==    indirectly lost: 4,067 bytes in 46 blocks.
==10307==      possibly lost: 1,556 bytes in 61 blocks.
==10307==    still reachable: 10,210 bytes in 309 blocks.
==10307==         suppressed: 0 bytes in 0 blocks.
==10307== Reachable blocks (those to which a pointer was found) are not shown.
==10307== To see them, rerun with: --leak-check=full --show-reachable=yes
==10307==Memcheck,一种内存错误检测器。
==10307==2002-2008年版权(C)和GNU GPL'd,朱利安·苏厄德等人。
==10307==使用libvexrev1884,一个用于动态二进制翻译的库。
==10307==OpenWorks LLP版权所有(C)2004-2008,GNU GPL'd。
==10307==使用valgrind-3.4.1-Debian,一个动态二进制检测框架。
==10307==2000-2008年版权(C)和GNU GPL'd,朱利安·苏厄德等人。
==10307==有关更多详细信息,请使用:-v重新运行
==10307== 
==10307== 
==10307==错误摘要:0个上下文中的0个错误(已抑制:1中的31个)
==10307==malloc/free:在出口处使用:422个块中的16021字节。
==10307==malloc/free:2198个allocs,1776个free,分配了74304个字节。
==10307==对于检测到的错误计数,请使用:-v重新运行
==10307==搜索指向422个未释放块的指针。
==10307==已检查8642848字节。
==10307== 
==10307==1个块中的44(12个直接,32个间接)字节在95个块中的丢失记录51中肯定丢失
==10307==at 0x40269EE:运算符新(无符号整数)(vg_替换_malloc.c:224)
==10307==by 0x46505EF:Dyninst::SymtabAPI::typeCollection::getAllTypes()(Collections.C:515)
==10307==by 0x46223F6:Dyninst::SymtabAPI::Symtab::getAllstdTypes()(Symtab.C:2182)
==10307==by 0x435E510:BPatch::BPatch()(在~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so中)
==10307==0x804914B:main(mutator.c:14)
==10307== 
==10307== 
==10307==1个块中的20个字节肯定会在丢失记录52(共95个)中丢失
==10307==at 0x40269EE:运算符新(无符号整数)(vg_替换_malloc.c:224)
==10307==by 0x438C3C4:BPatch_type::BPatch_type(Dyninst::SymtabAPI::type*)(在~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so中)
==10307==0x435E54F:BPatch::BPatch()(在~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so中)
==10307==0x804914B:main(mutator.c:14)
==10307== 
==10307== 
==10307==266(72个直接字节,194个间接字节)两个块中的字节肯定会在95块中的丢失记录69中丢失
==10307==at 0x40269EE:运算符新(无符号整数)(vg_替换_malloc.c:224)
==10307==by 0x438B6D7:BPatch_类型::BPatch_类型(char const*,int,BPatch_数据类)(在~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so中)
==10307==0x438BCAA:BPatch_type::createFake(char const*)(在~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so中)
==10307==by 0x435E4DB:BPatch::BPatch()(在~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so中)
==10307==0x804914B:main(mutator.c:14)
==10307== 
==10307== 
==10307==60个块中的1412个字节可能在95的丢失记录82中丢失
==10307==at 0x40269EE:运算符新(无符号整数)(vg_替换_malloc.c:224)
==10307==by 0x4817AD3:std::string::_Rep::_S_create(unsigned int,unsigned int,std::allocator const&)(in/usr/lib/libstdc++.so.6.0.10)
==10307==0x4818734:(在/usr/lib/libstdc++.so.6.0.10中)
==10307==by 0x48188A5:std::basic_string::basic_string(char const*,std::allocator const&)(in/usr/lib/libstdc++.so.6.0.10)
==10307==by 0x4665707:键入annotations.C(annotations.C:38)的全局构造函数
==10307==0x4666E3C:(在~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libsymtabAPI.so内)
==10307==0x45A85AF:(在~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libsymtabAPI.so内)
==10307==by0x400e343:(在/lib/ld-2.9.so内)
==10307==by0x400e473:(在/lib/ld-2.9.so内)
==10307==0x400084E:(在/lib/ld-2.9.so内)
==10307== 
==10307== 
==10307==3657(72个直接,3585个间接)字节在1个块中肯定会在95个块中的丢失记录84中丢失
==10307==at 0x40269EE:运算符新(无符号整数)(vg_替换_malloc.c:224)
==10307==by 0x435E583:BPatch::BPatch()(在~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so中)
==10307==0x804914B:main(mutator.c:14)
==10307== 
==10307== 
==10307==268(12个直接,256个间接)字节在1个块中肯定会在95个块中的85个丢失记录中丢失
==10307==at 0x40269EE:运算符新(无符号整数)(vg_替换_malloc.c:224)
==10307==by 0x465072F:Dyninst::SymtabAPI::builtInTypeCollection::getAllBuiltInTypes()(Collections.C:673)
==10307==by 0x46223C6:Dyninst::SymtabAPI::Symtab::getAllbuiltInTypes()(Symtab.C:2188)
==10307==by 0x435E598:BPatch::BPatch()(在~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so中)
==10307==0x804914B:main(mutator.c:14)
==10307== 
==10307== 
==10307==1个块中的144个字节可能在95的丢失记录91中丢失
==10307==at 0x4025092:calloc(vg\u replace\u malloc.c:397)
==10307==0x401128B:_dl_allocate_tls(in/lib/ld-2.9.so)
==10307==0x4A0F672:pthread_create@@GLIBC_2.1(在/lib/tls/i686/cmov/libpthread-2.9.so中)
==10307==by 0x441B852:InternalThread::createThread()(在~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so中)
==10307==by 0x44543B5:BPatch_asyncEventHandler::initialize()(在~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so中)
==10307==by 0x435E62A:BPatch::BPatch()(在~/Desktop/Masters/dyninstAPI/src/i386-unknown-linux2.4/lib/libdyninstAPI.so中)
==10307==0x804914B:main(mutator.c:14)
==10307== 
==10307==泄漏汇总:
==10307==肯定丢失:6个块中有188个字节。
==10307==间接丢失:46个块中有4067个字节。
==10307==