我在从代码中的文件读取配置时遇到问题。读取配置的方法如下所示:
void Configuration::readConfiguration()
{
std::string line;
std::ifstream configFile;
ConfigurationOptions * confOpt = new ConfigurationOptions();
InterpretateStrategy * doStrategy;
configFile.open("configuration");
if(!configFile.is_open())
{
throw "File opening error!";
}
configFile >> line;
while ( line.size() != 0 )
{
doStrategy = this->strategyMap[line];
doStrategy->interpretate(&configFile , confOpt);
line.clear();
configFile >> line;
}
this->connectionConfigure = new ConnectionConfigure(confOpt->getPortNumber(),
confOpt->getBufferSize());
this->databaseConfigure = new DataBaseConfigure(confOpt->getCellName(),
confOpt->getCellUser(),
confOpt->getAnonymousName(),
confOpt->getAnonymousUser());
this->interpreterConfigure = new InterpreterConfigure(confOpt->getWriteRawData(),
confOpt->getWriteInterpretatedData(),
confOpt->getTransactionSize());
delete(confOpt);
configFile.close();
}
当它执行然后线程正在启动程序时,此输出失败:
*** glibc detected *** ./eventReporter: free(): invalid pointer: 0x0000003c813540a8 ***
======= Backtrace: =========
/lib64/libc.so.6[0x3c8107164f]
/lib64/libc.so.6(cfree+0x4b)[0x3c8107587b]
./eventReporter[0x404cc9]
./eventReporter[0x404a22]
/lib64/libpthread.so.0[0x3ced80683d]
/lib64/libc.so.6(clone+0x6d)[0x3c810d4f8d]
======= Memory map: ========
00400000-0041b000 r-xp 00000000 08:08 1307697 /home/przemek/eventReporter/eventReporter
0061b000-0061c000 rw-p 0001b000 08:08 1307697 /home/przemek/eventReporter/eventReporter
148ef000-14910000 rw-p 148ef000 00:00 0
3c80c00000-3c80c1c000 r-xp 00000000 08:02 992032 /lib64/ld-2.5.so
3c80e1c000-3c80e1d000 r--p 0001c000 08:02 992032 /lib64/ld-2.5.so
3c80e1d000-3c80e1e000 rw-p 0001d000 08:02 992032 /lib64/ld-2.5.so
3c81000000-3c8114f000 r-xp 00000000 08:02 992072 /lib64/libc-2.5.so
3c8114f000-3c8134e000 ---p 0014f000 08:02 992072 /lib64/libc-2.5.so
3c8134e000-3c81352000 r--p 0014e000 08:02 992072 /lib64/libc-2.5.so
3c81352000-3c81353000 rw-p 00152000 08:02 992072 /lib64/libc-2.5.so
3c81353000-3c81358000 rw-p 3c81353000 00:00 0
3c81400000-3c81482000 r-xp 00000000 08:02 992601 /lib64/libm-2.5.so
3c81482000-3c81681000 ---p 00082000 08:02 992601 /lib64/libm-2.5.so
3c81681000-3c81682000 r--p 00081000 08:02 992601 /lib64/libm-2.5.so
3c81682000-3c81683000 rw-p 00082000 08:02 992601 /lib64/libm-2.5.so
3c81800000-3c81802000 r-xp 00000000 08:02 992599 /lib64/libdl-2.5.so
3c81802000-3c81a02000 ---p 00002000 08:02 992599 /lib64/libdl-2.5.so
3c81a02000-3c81a03000 r--p 00002000 08:02 992599 /lib64/libdl-2.5.so
3c81a03000-3c81a04000 rw-p 00003000 08:02 992599 /lib64/libdl-2.5.so
3c81c00000-3c81c14000 r-xp 00000000 08:02 992607 /lib64/libz.so.1.2.3
3c81c14000-3c81e13000 ---p 00014000 08:02 992607 /lib64/libz.so.1.2.3
3c81e13000-3c81e14000 rw-p 00013000 08:02 992607 /lib64/libz.so.1.2.3
3c88000000-3c8803b000 r-xp 00000000 08:02 992604 /lib64/libsepol.so.1
3c8803b000-3c8823b000 ---p 0003b000 08:02 992604 /lib64/libsepol.so.1
3c8823b000-3c8823c000 rw-p 0003b000 08:02 992604 /lib64/libsepol.so.1
3c8823c000-3c88246000 rw-p 3c8823c000 00:00 0
3c88800000-3c88815000 r-xp 00000000 08:02 992605 /lib64/libselinux.so.1
3c88815000-3c88a15000 ---p 00015000 08:02 992605 /lib64/libselinux.so.1
3c88a15000-3c88a17000 rw-p 00015000 08:02 992605 /lib64/libselinux.so.1
3c88a17000-3c88a18000 rw-p 3c88a17000 00:00 0
3c89600000-3c89615000 r-xp 00000000 08:02 992598 /lib64/libnsl-2.5.so
3c89615000-3c89814000 ---p 00015000 08:02 992598 /lib64/libnsl-2.5.so
3c89814000-3c89815000 r--p 00014000 08:02 992598 /lib64/libnsl-2.5.so
3c89815000-3c89816000 rw-p 00015000 08:02 992598 /lib64/libnsl-2.5.so
3c89816000-3c89818000 rw-p 3c89816000 00:00 0
3c89a00000-3c89b2d000 r-xp 00000000 08:02 992608 /lib64/libcrypto.so.0.9.8e
3c89b2d000-3c89d2c000 ---p 0012d000 08:02 992608 /lib64/libcrypto.so.0.9.8e
3c89d2c000-3c89d4d000 rw-p 0012c000 08:02 992608 /lib64/libcrypto.so.0.9.8e
3c89d4d000-3c89d51000 rw-p 3c89d4d000 00:00 0
3c8a200000-3c8a202000 r-xp 00000000 08:02 992602 /lib64/libkeyutils-1.2.so
3c8a202000-3c8a401000 ---p 00002000 08:02 992602 /lib64/libkeyutils-1.2.so
3c8a401000-3c8a402000 rw-p 00001000 08:02 992602 /lib64/libkeyutils-1.2.so
3c8aa00000-3c8aa11000 r-xp 00000000 08:02 992603 /lib64/libresolv-2.5.so
3c8aa11000-3c8ac11000 ---p 00011000 08:02 992603 /lib64/libresolv-2.5.so
3c8ac11000-3c8ac12000 r--p 00011000 08:02 992603 /lib64/libresolv-2.5.so
3c8ac12000-3c8ac13000 rw-p 00012000 08:02 992603 /lib64/libresolv-2.5.so
3c8ac13000-3c8ac15000 rw-p 3c8ac13000 00:00 0
3c8ba00000-3c8ba02000 r-xp 00000000 08:02 992606 /lib64/libcom_err.so.2.1
3c8ba02000-3c8bc01000 ---p 00002000 08:02 992606 /lib64/libcom_err.so.2.1
3c8bc01000-3c8bc02000 rw-p 00001000 08:02 992606 /lib64/libcom_err.so.2.1
3c8be00000-3c8be91000 r-xp 00000000 08:07 1526092 /usr/lib64/libkrb5.so.3.3
3c8be91000-3c8c091000 ---p 00091000 08:07 1526092 /usr/lib64/libkrb5.so.3.3
3c8c091000-3c8c095000 rw-p 00091000 08:07 1526092 /usr/lib64/libkrb5.so.3.3
3c8c600000-3c8c60d000 r-xp 00000000 08:02 992615 /lib64/libgcc_s-4.1.2-20080825.so.1
3c8c60d000-3c8c80d000 ---p 0000d000 08:02 992615 /lib64/libgcc_s-4.1.2-20080825.so.1
3c8c80d000-3c8c80e000 rw-p 0000d000 08:02 992615 /lib64/libgcc_s-4.1.2-20080825.so.1
3c8ca00000-3c8ca2c000 r-xp 00000000 08:07 1526093 /usr/lib64/libgssapi_krb5.so.2.2
3c8ca2c000-3c8cc2c000 ---p 0002c000 08:07 1526093 /usr/lib64/libgssapi_krb5.so.2.2
3c8cc2c000-3c8cc2e000 rw-p 0002c000 08:07 1526093 /usr/lib64/libgssapi_krb5.so.2.2
3c8ce00000-3c8ce08000 r-xp 00000000 08:07 1525508 /usr/lib64/libkrb5support.so.0.1
3c8ce08000-3c8d007000 ---p 00008000 08:07 1525508 /usr/lib64/libkrb5support.so.0.1
3c8d007000-3c8d008000 rw-p 00007000 08:07 1525508 /usr/lib64/libkrb5support.so.0.1
3c8d200000-3c8d224000 r-xp 00000000 08:07 1526091 /usr/lib64/libk5crypto.so.3.1
3c8d224000-3c8d423000 ---p 00024000 08:07 1526091 /usr/lib64/libk5crypto.so.3.1
3c8d423000-3c8d425000 rw-p 00023000 08:07 1526091 /usr/lib64/libk5crypto.so.3.1
3c8e200000-3c8e248000 r-xp 00000000 08:02 992609 /lib64/libssl.so.0.9.8e
3c8e248000-3c8e448000 ---p 00048000 08:02 992609 /lib64/libssl.so.0.9.8e
3c8e448000-3c8e44e000 rw-p 00048000 08:02 992609 /lib64/libssl.so.0.9.8e
3c8fa00000-3c8fae6000 r-xp 00000000 08:07 1525245 /usr/lib64/libstdc++.so.6.0.8
3c8fae6000-3c8fce5000 ---p 000e6000 08:07 1525245 /usr/lib64/libstdc++.so.6.0.8
3c8fce5000-3c8fceb000 r--p 000e5000 08:07 1525245 /usr/lib64/libstdc++.so.6.0.8
3c8fceb000-3c8fcee000 rw-p 000eb000 08:07 1525245 /usr/lib64/libstdc++.so.6.0.8
3c8fcee000-3c8fd00000 rw-p 3c8fcee000 00:00 0
3c91200000-3c91209000 r-xp 00000000 08:02 992600 /lib64/libcrypt-2.5.so
3c91209000-3c91408000 ---p 00009000 08:02 992600 /lib64/libcrypt-2.5.so
3c91408000-3c91409000 r--p 00008000 08:02 992600 /lib64/libcrypt-2.5.so
3c91409000-3c9140a000 rw-p 00009000 08:02 992600 /lib64/libcrypt-2.5.so
3c9140a000-3c91438000 rw-p 3c9140a000 00:00 0
3ced800000-3ced816000 r-xp 00000000 08:02 992010 /lib64/libpthread-2.5.so
3ced816000-3ceda16000 ---p 00016000 08:02 992010 /lib64/libpthread-2.5.so
3ceda16000-3ceda17000 r--p 00016000 08:02 992010 /lib64/libpthread-2.5.so
3ceda17000-3ceda18000 rw-p 00017000 08:02 992010 /lib64/libpthread-2.5.so
3ceda18000-3ceda1c000 rw-p 3ceda18000 00:00 0
3d02200000-3d02220000 r-xp 00000000 08:07 1525745 /usr/lib64/libpq.so.4.1
3d02220000-3d02420000 ---p 00020000 08:07 1525745 /usr/lib64/libpq.so.4.1
3d02420000-3d02422000 rw-p 00020000 08:07 1525745 /usr/lib64/libpq.so.4.1
2b9553d74000-2b9553d76000 rw-p 2b9553d74000 00:00 0
2b9553d8c000-2b9553ddf000 r-xp 00000000 08:07 1524951 /usr/lib64/libpqxx-2.6.9.so
2b9553ddf000-2b9553fdf000 ---p 00053000 08:07 1524951 /usr/lib64/libpqxx-2.6.9.so
2b9553fdf000-2b9553fe2000 rw-p 00053000 08:07 1524951 /usr/lib64/libpqxx-2.6.9.so
2b9553fe2000-2b9553feb000 rw-p 2b9553fe2000 00:00 0
2b9553feb000-2b9553fec000 ---p 2b9553feb000 00:00 0
2b9553fec000-2b95549ec000 rw-p 2b9553fec000 00:00 0
2b95549ec000-2b95549ed000 ---p 2b95549ec000 00:00 0
2b95549ed000-2b95553ed000 rw-p 2b95549ed000 00:00 0
2b95553ed000-2b95553ee000 ---p 2b95553ed000 00:00 0
2b95553ee000-2b9555def000 rw-p 2b95553ee000 00:00 0
7fffc927d000-7fffc9292000 rw-p 7ffffffe9000 00:00 0 [stack]
7fffc93fd000-7fffc9400000 r-xp 7fffc93fd000 00:00 0 [vdso]
ffffffffff600000-ffffffffffe00000 ---p 00000000 00:00 0 [vsyscall]
我确信这个问题与从这个文件中准确读取有关,因为:
- 当我评论
readConfiguration()
其中涉及文件的部分时没有问题 - 在同一个程序中,我正在写入其他文件,并且这些文件不会使任何内存失败。
我在 valgind 下运行这个程序,但没有Invalid write
. 此外,在 valgrind 下一切正常,完全没有运行时错误。
我对这个错误完全感到困惑......感谢您的帮助。
代码用g++编译
[przemek@fredek eventReporter]$ g++ -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --disable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=x86_64-redhat-linux
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-54)
操作系统:
[przemek@fredek eventReporter]$ uname -a
Linux fredek 2.6.18-348.1.1.el5.centos.plusxen #1 SMP Tue Jan 22 19:57:41 EST 2013 x86_64 x86_64 x86_64 GNU/Linux