我正在使用g ++ 6.3.0编译器在CentOS 7.5.1804上开发程序
运行程序时,它返回错误:
-bash-4.2$ ./lost_drv
*** Error in `./lost_drv': free(): invalid pointer: 0x0000000002375cf8 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x81499)[0x7f5c65e85499]
./lost_drv(_ZN5boost10filesystem4pathD2Ev+0x18)[0x521564]
/lib64/libc.so.6(__cxa_finalize+0x9a)[0x7f5c65e3df4a]
/lib64/libboost_filesystem.so.1.53.0(+0x7573)[0x7f5c68317573]
======= Memory map: ========
Valgrind发现这与boost :: filesystem :: path析构函数有关
-bash-4.2$ valgrind ./lost_drv
==32523== Memcheck, a memory error detector
==32523== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==32523== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==32523== Command: ./lost_drv
==32523==
==32523== Invalid free() / delete / delete[] / realloc()
==32523== at 0x4C2B1CD: operator delete(void*) (vg_replace_malloc.c:576)
==32523== by 0x521563: boost::filesystem::path::~path() (path.hpp:55)
==32523== by 0x73DBF49: __cxa_finalize (in /usr/lib64/libc-2.17.so)
==32523== by 0x5053572: ??? (in /usr/lib64/libboost_filesystem.so.1.53.0)
==32523== by 0x40101C9: _dl_fini (in /usr/lib64/ld-2.17.so)
==32523== by 0x73DBBD8: __run_exit_handlers (in /usr/lib64/libc-2.17.so)
==32523== by 0x73DBC26: exit (in /usr/lib64/libc-2.17.so)
==32523== by 0x73C444B: (below main) (in /usr/lib64/libc-2.17.so)
最后的return语句之后发生错误,因为所有内容都已清除。该程序显然可以在此之前运行。
这是一个扩展程序,但是我通过在主语句后紧跟一个return语句来对其进行了一些简化:
int main(int argc, char *argv[])
{
return 0;
...
我正在使用boost :: filesystem检查路径完整性...这样的代码:
try
{
boost::filesystem::path fn(ifilenm);
if(!boost::filesystem::exists(fn) || !boost::filesystem::is_regular_file(fn))
{
cout << "ERROR: Input file does not exist or isn't a file:\t" << ifilenm << "\n";
return -2;
}
}
catch (const boost::filesystem::filesystem_error& ex)
{
cout << "ERROR: Failed accessing input file. File doesn't exist or isn't a file or isn't accesible:\t" << ifilenm << "\n";
return -3;
}
在这种退化的情况下,哪些没有运行。在执行之前也没有初始化任何全局boost变量。
我已经尝试过使用系统Boost安装(1.53)以及针对使用g ++ 6.3编译器构建的boost 1.59的静态和动态链接进行此操作。行为相同。
更多...此可执行文件的另一个版本,可通过链接到其他第3方库来访问某些附加功能。该版本没有这个问题。
另一个数据点-如果我使用默认的CentOS 7编译器(g ++ 4.8.5)重建整个业务,则不会出现此错误。但这并不是一个整体选择,因为用于全额捐赠的第三方库需要g ++ 6
知道发生了什么吗? 谢谢