PDA

View Full Version : Xcode 4 memory problem




farmerdoug
Dec 10, 2011, 04:49 PM
I get a "Thread 1: Program received signal: :EXC_BAD_ACCESS" error whenever I run too many conditions in a for loop. I suspect this is a memory problem; I have checked my memory allocation and freeing of memory buffers but of course could have missed something. What is the easy way for a hacker like me to debug this?

Thanks.



robvas
Dec 10, 2011, 05:33 PM
Start out by posting the code that is giving you the error.

farmerdoug
Dec 10, 2011, 06:34 PM
Let's not go there. The code is somewhat proprietary and beside the point.
I should have just said what are good ways to look for what seem to be errors related to memory.

----------

Does anybody know anything about valgrind or memwatch? Is of them better or easier to use?

wrldwzrd89
Dec 10, 2011, 06:41 PM
Let's not go there. The code is somewhat proprietary and beside the point.
I should have just said what are good ways to look for what seem to be errors related to memory.

----------

Does anybody know anything about valgrind or memwatch? Is of them better or easier to use?
Lots of open-source projects use Valgrind to find and fix memory-related problems. I'd imagine that closed-source projects make use of it too. The key to using it is integrating it into your build process, to find these bugs BEFORE they make it to release-level code. As for Memwatch, I've not heard of this tool before.

farmerdoug
Dec 10, 2011, 06:58 PM
Thanks. I'll probably give it a try. I've used memwatch with makefiles but seem to remember having trouble implementing it.

jared_kipe
Dec 11, 2011, 11:25 AM
Too many conditions? like..

void foo(int x) {
int *y = &x;
for(y = 0; y < &x && *y == 1; y++) {
(void) 0;
}
}


Cause it runs fine (though it slowly) without the second compare.
But in trying to make it speed up, I cause EXEC_BAD_ACCESS... :(

Seriously though, if its repeatable every time, you're probably overflowing an array or something. Set break points earlier and earlier and just step through the code until your crash. You're probably dereferencing something you shouldn't, or overflowing an array due to poor control, or maybe having assignment when it should be comparison (= vs ==)

farmerdoug
Dec 11, 2011, 11:38 AM
problem solved
thanks