PDA

View Full Version : Memory corruption issue



roseicollis
16th February 2015, 12:24
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 valgrand (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

note: 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 same
Thank you so much.

d_stranz
16th February 2015, 18:29
Are you using the same compiler for building your app and building the external libraries with Eclipse? And I don't mean "yes, I'm using gcc", but are you using exactly the same binaries to build both? Are you sure that Qt Creator (or whatever) and Eclipse are using the same installation of your compiler, and are not each pointing to some local installed version?

ChrisW67
16th February 2015, 21:28
You get this sort of output if your double free an object or free/delete a stack based object.

roseicollis
17th February 2015, 08:23
Hi all :)


Are you using the same compiler for building your app and building the external libraries with Eclipse? And I don't mean "yes, I'm using gcc", but are you using exactly the same binaries to build both? Are you sure that Qt Creator (or whatever) and Eclipse are using the same installation of your compiler, and are not each pointing to some local installed version?

Short answer: I don't know. Hehe. I just did what a mate told me to so as it worked I forgot about it. What I don't understand is why this worked fine before but not now. I'll try to find out which version use every program. Thank you!


You get this sort of output if your double free an object or free/delete a stack based object.
The thing is that I didn't change my code, only updated the external libraries. Could it be there the problem? It's weird because the change was only a couple of gets and sets so no mallocs or frees news.
What do you mean with: "a stack based object" ?

Thank you so much!

wysota
17th February 2015, 09:15
"Running Valgrind" does not fix your code, it's not a magic wand. Valgrind points out problems in your source code which you have to fix yourself.

roseicollis
17th February 2015, 10:21
Hi wysota, yes I realized that when it crashes this time, but I don't know what do I have to fix exactly.

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.

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

wysota
17th February 2015, 11:31
I think the log is pretty much self explanatory. You are accessing memory which you have not allocated. Look at the lines in your code where Valgrind points and see what you do there. Either BaseWizard or CCClass* are not implemented correctly.

roseicollis
17th February 2015, 15:28
I think the log is pretty much self explanatory. You are accessing memory which you have not allocated. Look at the lines in your code where Valgrind points and see what you do there. Either BaseWizard or CCClass* are not implemented correctly.

Yes, it is. But I had no idea why so that's why I asked here.. maybe someone had a better idea about my problem and how /where could I find the solution.

As the last version of the external library works fine, I deduce that the problem is there so I'll let the workmate who made it to fix it.


Thank you for your help! I'll tell him now all u said that it could be.

wysota
17th February 2015, 21:45
Yes, it is. But I had no idea why so that's why I asked here.. maybe someone had a better idea about my problem and how /where could I find the solution.
Not seeing those lines it is hard to guess what's wrong with them :)


As the last version of the external library works fine, I deduce that the problem is there so I'll let the workmate who made it to fix it.
I.... wouldn't be so sure if I were you.