我正在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)
我需要理解这个输出。谁能帮我理解这个错误,这里有什么问题?
谢谢。
首先,您应该开始修复Invalid read
错误。它们是分段错误最可能的原因,这与内存泄漏无关。
Valgrind 输出中的第一个Invalid read
意味着sqlite3SafetyCheckSickOrOk
调用引用了之前已经释放的一些内存。下面打印了发生它的确切调用堆栈。这看起来很奇怪,因为它发生在sqlite3_close
中,而不是指释放的记忆。可能这是 sqlite 错误。
第二个Invalid read
表示在 CMdcevMM::loadXmlString
中引用 NULL 指针。检查您的代码。