Problems with freeing allocated memory (freeRTOS v.8.0)

kudl4t4 wrote on Friday, August 29, 2014:

My code looks like

/*------ VARIABLES ------*/
uint8_t how;
typedef struct {
  uint8_t *nfcid;
} Test;

typedef union {
  Test here;
} Haha;

Haha *haha;

/*------ FUNCTIONS ------*/
void memoryAlloc( Haha **haha ) {
  Haha *h =(Haha *)pvPortMalloc( (1) * sizeof(Haha) );
  *haha = h;

  uint8_t *r =(uint8_t *)pvPortMalloc( (1) * sizeof(uint8_t) );
  *r = 0x0F+how;
  (*haha)->here.nfcid = r;
}

void freeAlloc( Haha *haha ) {
  vPortFree(haha->tutaj.nfcid);
  vPortFree(haha);
}

/*------ MAIN ------*/
void main() {
  how++;
  memoryAlloc(&haha);
  freeAlloc(haha);
}

and it seems like vPortFree doesn’t free memory. What may be the problem?

davedoors wrote on Friday, August 29, 2014:

Your use of pointers to pointers is too mind bending for me to be able to work it out, and I don’t know where tutaj came from at all. Try creating a dummy application is something like MingW that runs the code with normal C lib mallocs and frees then step the code to see what it’s doing.