[Solved] Memory corruption problem
-
wrote on 16 Feb 2015, 12:06 last edited by
Hi!
I'm doing a gui app with Qt 4.8.5 and c++ on a fedora 18. For that I am using also some external libraries compiled with eclipse.
Until last week it worked all okey, I could call and use that external library functions with no problem.
The first error ocurred last week when a memorry corruption appeared with something like this (I can't remember exactly all):
@
** glibc detected [...] malloc(): memory corruption: 0x10013ff8 ***
@I clean and run qmake and nothing.. and then I run valgrind (I still don't know what is that exactly for but it worked).
Today I got some error like this and did same and it worked but lately again I had:
@
*** glibc detected *** /home/sg/Documents/Projects/myApp/build-myApp-Desktop-Debug/myApp: malloc(): memory corruption: 0x0986f260 ***
@And valgrind did nothing so lookign for internet I saw that it could be fixed with a external valgrind so I follow this instructions: "Valgrind":http://developer.nokia.com/community/wiki/Using_valgrind_with_Qt_Creator
And it solved my problem... BUT now my app runs well if I run it like the example (running vlagrind) but if I try to run it like I was doing before (Just run debug/release of myApp) then the glibc memorry corruption appears again... and that seems to be a very bad problem because ofc the .exe will not run ...
so... any idea of the problem? The only difference on the external libraries this time is that they have a couple of get and sets more so there is no malloc or array or something like that new that could cause a memor acces problem
edit: in the argumetn line I had to put:
@
-q --tool=memcheck --leak-check=full --leak-resolution=low ./myApp
@
with no supression because it gaved me an erro... tried also with qt48 but the sameThank you so much.
-
wrote on 17 Feb 2015, 10:25 last edited by
For more information:
Valgrind prints some things like this on the console:
@
==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)@
There are like 5 times more that information and then it throws the program. But if I run it without valdring then it says the glibc malloc() memory corruption. (And there have NOT been any changes about creating mallocs or frees or deletes or something like this).
note: About that references... main and basewizard are my classes on Qt (main.cppp and basewizard is the QWizard), and Class1,2,3 and CSection are from the external libraries
-
Hi,
[quote author="roseicollis" date="1424088398"]
@
*** glibc detected *** /home/sg/Documents/Projects/myApp/build-myApp-Desktop-Debug/myApp: malloc(): memory corruption: 0x0986f260 ***
@
[/quote]That probably means a bug was detected in your code or the library's code. Perhaps your program is writing to a memory location where it's not supposed to.See http://stackoverflow.com/questions/19057079/glibc-detected-malloc-memory-corruption-in-c for an example.
[quote author="roseicollis" date="1424088398"]And valgrind did nothing so lookign for internet I saw that it could be fixed with a external valgrind so I follow this instructions: [/quote]Valgrind itself doesn't fix anything. It only analyzes your code to help you find the bug.
Anyway, run a debug build through a debugger (like GDB) -- it will run your program, and then stop when it detects a problem.
-
wrote on 17 Feb 2015, 11:36 last edited by
Hi JKSH,
[quote author="JKSH" date="1424172471"]
See http://stackoverflow.com/questions/19057079/glibc-detected-malloc-memory-corruption-in-c for an example.
[/quote]Already did but it didn't help me with my problem.
[quote author="JKSH" date="1424172471"]Valgrind itself doesn't fix anything.
[/quote]
Yes, realized later when problem happened again ^^''[quote author="JKSH" date="1424172471"]
Anyway, run a debug build through a debugger (like GDB) -- it will run your program, and then stop when it detects a problem.[/quote]
Ok, thanks for the tip, I'll see now how to do it :)Edit:
I oppened a terminal were I have the debug version, put gdb myApp and then run and got the same: Just 2 lines which are:
@
*** glibc detected *** /home/sgarcia/Documents/Proyectos/Wizard17/build-Wizard17-Desktop-Debug/Wizard17: malloc(): memory corruption: 0x081a1120 ***
*** glibc detected *** /home/sgarcia/Documents/Proyectos/Wizard17/build-Wizard17-Desktop-Debug/Wizard17: malloc(): memory corruption: 0x081a1120 ***
@Thank you so much!
-
[quote author="roseicollis" date="1424172993"]I oppened a terminal were I have the debug version, put gdb myApp and then run and got the same: Just 2 lines which are:
@
*** glibc detected *** /home/sgarcia/Documents/Proyectos/Wizard17/build-Wizard17-Desktop-Debug/Wizard17: malloc(): memory corruption: 0x081a1120 ***
*** glibc detected *** /home/sgarcia/Documents/Proyectos/Wizard17/build-Wizard17-Desktop-Debug/Wizard17: malloc(): memory corruption: 0x081a1120 ***
@Thank you so much![/quote]Use Qt Creator's debugging function (on the bottom-left corner, click on the green triangle that has a bug icon on top). If the bug is in your code, Qt Creator can show you the line in the .cpp file where the memory corruption is detected.
Looking at your Valgrind output though, the bug seems to be in the library (CSection constructor)
Just in case, can you show us your code? How does BaseWizard include CClass2, CClass1 and CSection?
-
wrote on 17 Feb 2015, 12:55 last edited by
[quote author="JKSH" date="1424175228"]
Use Qt Creator's debugging function (on the bottom-left corner, click on the green triangle that has a bug icon on top). If the bug is in your code, Qt Creator can show you the line in the .cpp file where the memory corruption is detected.
[/quote]
Yes yes, I know how to debug normally. In fact, now there were you say its a little pc image were you can choice if release or debug and now, if myApp or /usr/bin/Valgrind. And for those who love shortcuts like me: Ctr+R for release and F5 for debug ;)[quote author="JKSH" date="1424175228"]
Looking at your Valgrind output though, the bug seems to be in the library (CSection constructor)
[/quote]
I think the problem is in the library because what I did was:- Run my program to see it still works: Fine until here.
- Update libraries on local.
- Open eclipse and built them again. [the *.a will be updated so I don't have to do anything else.
- Change one call to a func (cause its name changed on the library), and run the program again: Crashes HERE! :(
Then I commented the line I changed and still crashes so I deduced that the problem is on the library BUT as I said, the only change there was a couple of sets and gets (and the change of a func name).. no new mallocs, or frees...
Maybe is in CSection? Maybe.. but it doesn't seems to... and moreover there are other pharagraphs like this of valgrind. This example I put there was the first one and the 4th
[quote author="JKSH" date="1424175228"]
Just in case, can you show us your code? How does BaseWizard include CClass2, CClass1 and CSection?
[/quote]Basically I do the #include of the file I need:
@
#include "CClass2"
#include "CClass1"
@Then I call:
@
CClass2::Initialize();
@which is the line valgrind refers with:
@
==2848== by 0x807C800: CClass2::Initialize() (Class1.cpp:51)
@And then in my code I use:
@
CClass1 *myvar = CClass2::GetOfTheVariable();
@ -
[quote author="roseicollis" date="1424177743"]I think the problem is in the library because what I did was:
- Run my program to see it still works: Fine until here.
- Update libraries on local.
- Open eclipse and built them again. [the *.a will be updated so I don't have to do anything else.
- Change one call to a func (cause its name changed on the library), and run the program again: Crashes HERE! :([/quote]So what happens if you revert to the old version of the library?
-
wrote on 17 Feb 2015, 15:23 last edited by
[quote author="JKSH" date="1424178116"]So what happens if you revert to the old version of the library?
[/quote]
I was waiting because I could not revert it (need something from a workmate), but now that I could and I did it it works. So the problem definitely is on the last change of the external library.
I'll tell my mate to fix it :) So the problem is more or less solved for me.
Thank you so much!
-
You're welcome. :)
1/9