Forum Discussion
Altera_Forum
Honored Contributor
13 years agoMalloc till it fails, crashes, bug in Malloc?
I'm trying to write some code that will determin how much "free" memory the system still has. I created some somewhat speedy code, but really the simple code could just run a loop like this: ...
Altera_Forum
Honored Contributor
13 years agoThat last free in your function should be wrapped with an if statement guarding it from trying to free an unallocated pointer. I suspect you are running into a stack and heap collision like DSL warned you of.
A common way for detecting a stack and heap collision is to fill your memory with some known pattern (you pick), then populate it with your code, run the code, then take a look at the memory after to see if your pattern is still around. If the pattern is gone then there was most likely a stack + heap collision.