Requires some allocation and deallocation of large arrays on a PIC32MX775

I am currently working on a project that requires some allocation and deallocation of large arrays on a PIC32MX775F256L: http://www.kynix.com/Detail/347322/PIC32MX775F256L-80I%2FPF.html. I have a dedicated heap memory size of 1500 bytes, which should be more than sufficient and I have previously had the system allocating and deallocating memory correctly when using standard float types. However, I have recently introduced a new variable type:

typedef struct{
char index;
float gain;
float freq;   }RM_EQ_SORT_ELEMENT;

With this replacing three separate arrays I have had problems deallocating the memory using the ‘free()’ function ever since. An example of the arrays and how I’m trying to free them is below:

float* freq = (float*)malloc(NO_OF_FREQS*sizeof(float)); // For the unsorted average frequency
RM_EQ_SORT_ELEMENT* sortArray = (RM_EQ_SORT_ELEMENT*)malloc(NO_OF_FREQS*sizeof(RM_EQ_SORT_ELEMENT));

//**Some more code here that uses the arrays**

if(freq != NULL){
   free(freq);
}

if(sortArray != NULL){
   free(sortArray);
}

Whilst debugging, the code will jump into the ‘excep_bp’ loop found at the bottom of the included exceptions.c file, when the PIC32 hits either of the above free statements. If their order is changed the same result occurs.

Are there any common problems that might occur when deallocating memory like this with a PIC32? Also I understand that I might be able to debug this problem more thoroughly, any advice on what to do in this situation would help.

Let me check the FCC lesson that talks about Embedded Microcrontrollers… err, can’t find it :frowning: