View previous topic :: View next topic |
Author |
Message |
joseosanchez
Joined: 26 Jul 2004 Posts: 2
|
free function hangs up PIC |
Posted: Mon Jul 26, 2004 3:09 pm |
|
|
Hi I implemented a linked list on my PIC which contains the sensors connected to the CAN bus, however, when I unplug a sensor and I try to remove the sensor from the list, sometimes it hangs up when it calls the free function. I debbuged the code using ICD and everythings seems to be ok until the free function is called where it stays forever.
My remove functios is as follows:
int removeSensor(int16 id)
{
struct sensors *curr=NULL, *prev=NULL;
if(selectsensor(id)==NOTFOUND)
return(NOTFOUND);
if(first->id==id)
{
curr=first;
first=curr->next;
}
else
{
prev=first;
curr=first->next;
while(!(curr->id==id))
{
prev=curr;
curr=curr->next;
}
prev->next=curr->next;
}
free(curr);
anz-=1;
return(OK);
}
I hope someone has an idea how to solve this problem.
thanks
Jose |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Mon Jul 26, 2004 5:08 pm |
|
|
The code for free() is in the STDLIBM.H file. Debug your code, and instead of jumping over the free() function step through it. This way you shuold be able to figure out what exactly is causing the problem. |
|
|
joseosanchez
Joined: 26 Jul 2004 Posts: 2
|
free function hangs up PIC |
Posted: Tue Jul 27, 2004 8:31 am |
|
|
I was debbuging the code and I noticed that it hangs up in the function traverse() located in stdlibm.h and specially in a function that traverse calls which is remove_node located in memmgmt.c. For the moment being I removed the free function and the PIC does not hangs but of course I am leaving spaces of memory without allocation which is not right, but I have no idea what to do to solve this problem.
any ideas.
Jose |
|
|
|