This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

malloc causes crash

hi there,

I'm developing a C program for an embedded device in order to use it as a pad which is able to recognize handwriting. In short, the program is supposed to extract several features of the signature and calculate a biometric hash.

Sadly the program keeps crashing as soon as I use malloc or realloc. Since I'm not able to debug the malloc function I can't really see the cause for that.

        int32_t *foobar;

        foobar = malloc( sizeof(int32_t) );   //CRASH

I don't even know where to start looking for a solution, except for google which didn't provide the answer I was looking for, so maybe anyone here could give me a solution or a hint to fix it.

If there is some important information missing please just tell so and I will see if I can add it.

I'm working with Keil yVision:

stats for the embedded device
ARM-7 32bit Architecture
NXP (Philips) LPC 2368
72 MHz
512 kB on-chip Flash
58kB SRAM

  • Have you configured a heap for your project?

    If yes - try and cut away code from your project until you can get the smallest possible program that still crashes - chances are that you have an error somewhere that overwrites some critical structure for the runtime library.

  • awww, yes I configured the heap, just saw that I transposed two digits -.-

    Sadly I also realized there are some loops where I reallocate some memory. This turns out to cause the actual Heap-Overflow.

    It will be hard to find a workaround, cause I'm using the heap for dynamic arrays, which seem to be much larger than expected, where all entries are equally important.

    Thanks for the hint, after all it wasn't so hard to find the cause for the problem.

    Bye

  • That is the fundamental problem with dynamic allocation!

    And it's a particular difficulty for embedded systems as you can't just put up a user dialogue saying, "out of memory"!

    This is why dynamic allocation may be best avoided in embedded systems...