|
-
March 31st, 2009, 02:30 AM
#1
Tricky Memory Related Segmentation Fault
Hello,
I have a very strange issue with a program I'm trying to debug. First of all, the program is a monte carlo simulation, which means that it does exactly the same process over and over again, involving random numbers, with different random seeds. From a purely algorithmic standpoint, if the code is correct than the simulation should always run fine, and if its wrong then it should fail on the very first simulation. However, I have a bizarre combination of issues.
First off, there appears to be a memory leak. The RAM the program uses increases rapidly until it hits about 400 megs. This is still only 20% of my system however. At this point it crashes. If it was purely a memory allocation issue however, you would expect that with different parameters it would crash at different points in the code. However it does not. It always crashes on the exact same line (verified using a debugger). This lame is a simple array copying statement, and it causes a seg fault, array out of bounds because the array that I am trying to assign values to is a null pointer. Hence even though I am accessing it at zero, it causes a seg fault.
Since the pointer is null, the obvious thing is that the array hasn't been new-ed yet or that it has already been deleted. However, it worked on the first n identical iterations of my simulation, but not on this one. What gives? Why would a memory leak cause an array out of bounds error? Could a memory leak eventually prevent an array from being allocated properly? Why always the same array?
On top of it the crashes are not even consistent in the sense that if i start at seed 1 with some givne settings, it will crash at seed 31. If i start at seed 20 however with the same settings, it no longer crashes at seed 31. This seems to imply that whatever the problem is, it is heavily memory related. Yet it is hard to reconcile that fact with the fact that it seems to always crash in the same place.
Does anyone have some general suggestions on how I can track this down, software I can use, things to look out for, anything? I've been hammering away at it with GDB and staring and staring at lines of source code but its very hard, everything seems to be deleted properly. I make sure that all the classes de-allocate all their memory in the destructors and I make sure all the destructors are called. Don't know what to do any more...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|