Problem with using malloc in link lists (urgent ! help please)

Posted by Abhinav on Stack Overflow See other posts from Stack Overflow or by Abhinav
Published on 2010-06-02T01:22:49Z Indexed on 2010/06/02 1:23 UTC
Read the original article Hit count: 285

Filed under:
|
|
|
|

I've been working on this program for five months now. Its a real time application of a sensor network. I create several link lists during the life of the program and Im using malloc for creating a new node in the link. What happens is that the program suddenly stops or goes crazy and restarts. Im using AVR and the microcontroller is ATMEGA 1281. After a lot of debugging I figured out that that the malloc is causing the problem. I do not free the memory after exiting the function that creates a new link so Im guessing that this is eventually causing the heap memory to overflow or something like that. Now if I use the free() function to deallocate the memory at the end of the function using malloc, the program just gets stuck when the control reaches free(). Is this because the memory becomes too clustered after calling free() ?

I also create reference tables for example if 'head' is a new link list and I create another list called current and make it equal to head.

table *head; table *current = head;

After the end of the function if I use free

free(current); current = NULL:

Then the program gets stuck here.

I dont know what to do. What am I doing wrong? Is there a way to increase the size of the heap memory Please help...

© Stack Overflow or respective owner

Related posts about dynamic

Related posts about lists