What can cause this crash?

I have a C ++ program (GCC) and when I add one or more int members to an abstract base class, the program starts to crash. In the case at hand, it seems that by adding this member, the member in the derived class gets out of initialization (or gets caught at some point). If I add more members, it starts (not) to work differently. This is all very strange because the member is never used anywhere. I can comment that one line and the program recompiles just fine and works without error.

The whole program is ~ 3KLOC and it is very difficult to remove it.

I have absolutely no idea where to start looking. Any ideas?


Update

I found the problem: free

-ing malloc

-ed memory and delete

-ing new

-ed memory are unsafe in the same program.

+2


source to share


5 answers


Off the top of my head, without seeing any code (see comments on your question), I would suggest a rogue pointer that usually stomps on something you don't notice, but the introduction of a new member makes it stomp on what you are doing notice ...



Try adding members of different sizes or more (unused) int

members, or maybe a line in the form: const char xxx[50];

to reserve more space.

+6


source


99 times out of 100 I find that if you change the data structure of the class and start getting weird crashes then the assembly dependencies are not quite correct i.e. you need to rebuild something that for some reason is not recoverable.



If it's not a big pain to completely clean up and rebuild your entire project, then I would give this and then we can work this answer out.

+7


source


A little more information about the crash would be helpful, since there are multiple ways a program can crash. However, the first thing I do on Linux if I suspect it might be a memory error is to run the program through Valgrind (Memcheck) and see what it can tell me.

Also like a shot in the dark, does your build system build dependencies correctly? One possibility is that you are modifying the abstract class, but not recompiling all the source files that depend on the abstract class, which can be problematic.

+4


source


Try running the program in gdb.

gdb your_executable

      

Then press "r" then enter when your code fails, you can press "bt" then enter to see the offending line of code.

+1


source


After you changed the class, did you recompile the whole source?

If you've only recompiled the base or derived class (not sure where you would put the new int), then all other objects are the wrong size for your class. You need to delete all object files and restore them.

+1


source







All Articles