Well, I'm having a little problem, I'm implementing a simple A *. When I pass the item already checked to the closed list and do the deallocation of the open list item, it is giving undeclared pointer error ... The error is this pointer being freed was not allocated
, but I already checked my logic and also checked if I I was handing out a pointer that actually had been declared with malloc
and it really was! I even use the same code, another code deallocation code. I practically copied and pasted each other and what was already done and does not give problems, but in the new gives ... See:
This is the deallocation code that is working (I use this code to animate too):
void anima(Lista* li, int frame, int agFramex, int agFramey){
Elem* no = (Elem*) malloc(sizeof(Elem));
Elem* ant = (Elem*) malloc(sizeof(Elem));
no = (*li);
ant = no;
while(no != NULL){
if(no->dados.y > ALT+200){
if(no == *li){
*li = no->Prox;
free(no);
no = *li;
} else if(no->Prox == NULL){
ant->Prox = no->Prox;
free(no);
no = ant->Prox;
} else {
ant->Prox = no->Prox;
free(no);
no = ant->Prox;
}
} else {
no->dados.y += no->dados.vel;
al_draw_bitmap_region(no->dados.Img, agFramex*frame, agFramey*frame, frame, frame, no->dados.x, no->dados.y, 0);
ant = no;
no = no->Prox;
}
}
}
This is the code that is not: ( atual
and AbList
exist, they are as function parameter up there, since the function was very extensive I chose not to put it whole here, in the previous moments of the function eu I put elements in the list just that):
Elc* rem = (Elc*) malloc(sizeof(Elc));
Elc* mer = (Elc*) malloc(sizeof(Elc));
rem = (*AbList);
mer = rem;
while(rem != NULL){
if(rem->dados.x == atual.dados.x && rem->dados.y == atual.dados.y){
if(rem == *AbList){
*AbList = rem->Prox;
free(rem);
rem = *AbList;
} else if(rem->Prox == NULL){
mer->Prox = rem->Prox;
free(rem);
rem = mer->Prox;
} else {
mer->Prox = rem->Prox;
free(rem);
rem = mer->Prox;
}
} else {
mer = rem;
rem = rem->Prox;
}
}
As you can see, the codes are very similar, but for some reason in this I get the error and in the other not ...
Note: I use Macbook Pro I am coding in C using Allegro.