我在fedora 18上用Qt 4.8.5和c ++做了一个gui应用程序。为此我还使用了一些用eclipse编译的外部库。
直到上周它才起作用,我可以调用并使用外部库函数,没有任何问题。
上周出现了第一个错误,当时有一个像这样的记忆腐败出现(我记不清楚):
** glibc detected [...] malloc(): memory corruption: 0x10013ff8 ***
我清理并运行qmake而没有...然后我运行valgrand(我仍然不知道究竟是什么,但它有效)。
今天我得到了一些像这样的错误并做了同样的事情但是它起作用但最近又有了:
*** glibc detected *** /home/sg/Documents/Projects/myApp/build-myApp-Desktop-Debug/myApp: malloc(): memory corruption: 0x0986f260 ***
并且valgrind什么也没做,所以看看互联网我看到它可以用外部valgrind修复,所以我按照这个说明进行操作:Valgrind
它解决了我的问题...但是现在我的应用程序运行良好,如果我像示例(运行vlagrind)一样运行它,但如果我尝试像以前那样运行它(只需运行myApp的调试/发布),那么glibc记忆腐败再次出现......这似乎是一个非常糟糕的问题,因为.exe将无法运行......
所以......对这个问题有什么看法?这次外部库的唯一区别是它们有一些get和sets,所以没有malloc或数组或类似new的东西可能导致memor access问题
注意:在参数行中我必须放置:
-q --tool=memcheck --leak-check=full --leak-resolution=low ./myApp
没有任何抑制因为它给了我一个错误...也尝试使用qt48,但同样。
Valgrind在控制台上输出这样的东西:
==2848== Invalid write of size 4
==2848== at 0x435CA6E3: pthread_mutex_init (in /usr/lib/libpthread-2.16.so)
==2848== by 0x808A450: TLib::CSection::CSection() (Section.cpp:11)
==2848== by 0x80773D6: CClass1::CClass1() (Class1.cpp:15)
==2848== by 0x807C642: CClass2::CClass2() (Class2.cpp:21)
==2848== by 0x807C800: CClass2::Initialize() (Class1.cpp:51)
==2848== by 0x805A346: BaseWizard::BaseWizard(QWidget*) (basewizard.cpp:49)
==2848== by 0x80523A2: main (main.cpp:26)
==2848== Address 0x5b09f14 is 0 bytes after a block of size 292 alloc'd
==2848== at 0x4008AAD: operator new(unsigned int) (vg_replace_malloc.c:292)
==2848== by 0x807C638: CClass2::CClass2() (Class2.cpp:21)
==2848== by 0x807C800: CClass2::Initialize() (Class2.cpp:51)
==2848== by 0x805A346: BaseWizard::BaseWizard(QWidget*) (basewizard.cpp:49)
==2848== by 0x80523A2: main (main.cpp:26)
==2848== Invalid read of size 4
==2848== at 0x438EBA44: std::string::_M_mutate(unsigned int, unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.17)
==2848== by 0x438EBC32: std::string::_M_replace_safe(unsigned int, unsigned int, char const*, unsigned int) (in /usr/lib/libstdc++.so.6.0.17)
==2848== by 0x438EBCDB: std::string::assign(char const*, unsigned int) (in /usr/lib/libstdc++.so.6.0.17)
==2848== by 0x438EBF16: std::string::operator=(char const*) (in /usr/lib/libstdc++.so.6.0.17)
==2848== by 0x80767B4: CClass3::CClass3() (Class3.cpp:39)
==2848== by 0x807C6E2: CClass2::CClass2() (Class2.cpp:34)
==2848== by 0x807C800: CClass2::Initialize() (Class2.cpp:51)
==2848== by 0x805A346: BaseWizard::BaseWizard(QWidget*) (basewizard.cpp:49)
==2848== by 0x80523A2: main (main.cpp:26)
==2848== Address 0x5b15efc is 4 bytes after a block of size 48 alloc'd
==2848== at 0x4008AAD: operator new(unsigned int) (vg_replace_malloc.c:292)
==2848== by 0x807C6D8: CClass2::CClass2() (Class2.cpp:34)
==2848== by 0x807C800: CClass2::Initialize() (Class2.cpp:51)
==2848== by 0x805A346: BaseWizard::BaseWizard(QWidget*) (basewizard.cpp:49)
==2848== by 0x80523A2: main (main.cpp:26)
这些信息有5倍以上然后它会抛出程序。但是,如果我在没有valdring的情况下运行它,那么它会说glibc malloc()内存损坏。 (并且没有关于创建malloc或释放或删除或类似的东西的任何更改。)
注意:关于那些引用... main和basewizard是我在Qt上的类(main.cppp和basewizard是QWizard),Class1,2,3和CSection来自外部库
非常感谢你。