1

我正在 Eclipse 中构建一个 C++ 项目。它使用 SQLITE3 作为数据库,使用 libxml 从 XML 文件中读取特定数据。代码编译良好并生成可执行文件。但是,当我运行二进制文件时,它会以这条消息终止Segmentation fault (core dumped)

当我运行 Valgrind 分析器来检测内存泄漏的位置时,我得到了一个我无法理解的巨大日志文件。

    ==4960== Invalid read of size 4
    ==4960==    at 0x41C6EB7: sqlite3SafetyCheckSickOrOk (sqlite3.c:22048)
    ==4960==    by 0x41EADCA: sqlite3_close (sqlite3.c:112926)
    ==4960==    by 0x804A551: Database::close() (CEMDAPnew.cpp:133)
    ==4960==    by 0x805D2F3: CDataCoordinator::ReadVehicleMakeData(std::string) (DataCoordinator.cpp:2709)
    ==4960==    by 0x80689D4: main (GauravWithoutMPI.cpp:36)
    ==4960==  Address 0x4dc1fd0 is 64 bytes inside a block of size 512 free'd
    ==4960==    at 0x402B06C: free (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
    ==4960==    by 0x41B520F: sqlite3MemFree (sqlite3.c:15252)
    ==4960==    by 0x41A2DF0: sqlite3_free (sqlite3.c:18986)
    ==4960==    by 0x41EB0B4: sqlite3_close (sqlite3.c:113040)
    ==4960==    by 0x804A551: Database::close() (CEMDAPnew.cpp:133)
    ==4960==    by 0x805D2F3: CDataCoordinator::ReadVehicleMakeData(std::string) (DataCoordinator.cpp:2709)
    ==4960==    by 0x80689D4: main (GauravWithoutMPI.cpp:36)
    ==4960== 
    ==4960== Conditional jump or move depends on uninitialised value(s)
    ==4960==    at 0x4532DD8: inflateReset2 (in /lib/i386-linux-gnu/libz.so.1.2.3.4)
    ==4960==    by 0x4532EC7: inflateInit2_ (in /lib/i386-linux-gnu/libz.so.1.2.3.4)
    ==4960==    by 0x512FE6B: ???
    ==4960== 
    ==4960== Conditional jump or move depends on uninitialised value(s)
    ==4960==    at 0x4532DD8: inflateReset2 (in /lib/i386-linux-gnu/libz.so.1.2.3.4)
    ==4960==    by 0x4532EC7: inflateInit2_ (in /lib/i386-linux-gnu/libz.so.1.2.3.4)
    ==4960==    by 0x5056E135: ???
    ==4960== 
    ==4960== Invalid read of size 4
    ==4960==    at 0x80BD81C: CMdcevMM::loadXmlString(_xmlNode*, _xmlDoc*, unsigned char*) (ModelModule.cpp:2849)
    ==4960==    by 0x810D73A: CSimCoordinator::LoadXmlString(char const*) (simCoordinator.cpp:8313)
    ==4960==    by 0x8068A4E: main (GauravWithoutMPI.cpp:45)
    ==4960==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
    ==4960== 
    ==4960== 
    ==4960== Process terminating with default action of signal 11 (SIGSEGV)

我需要理解这个输出。谁能帮我理解这个错误,这里有什么问题?

谢谢。

4

1 回答 1

2

首先,您应该开始修复Invalid read错误。它们是 Segmentation fault 最可能的原因,与内存泄漏无关。

Valgrind 输出中的第一个Invalid read表示该sqlite3SafetyCheckSickOrOk调用引用了一些先前已释放的内存。它发生的确切调用堆栈打印在下面。这看起来很奇怪,因为它发生的时候sqlite3_close比指的是释放的内存。可能这是 sqlite 错误。

第二个Invalid read意思是引用 NULL 指针CMdcevMM::loadXmlString。检查你的代码。

于 2012-09-17T09:32:17.760 回答