I am having this error while running my program glibc detected * ./out: double free or corruption (!prev): 0x082a7dd0 the problem occurs when tryng to free a pointer, here are some parts of code:
//Structure to define an existing lightpath in the network
struct existing_lightpath{
int* route;
int wavelength;
int* edges;
int num;
double LAR;
double IAR;
int LAR_group[100];
int IAR_group[100];
struct existing_lightpath* next_lightpath;
};
and this code for deleting the node from linked list
if(event_type_cur == 0 && existing_lightpath_list != NULL){
temp = existing_lightpath_list;
previous = NULL;
while(temp->num != lightpath_num_cur && temp->next_lightpath != NULL){
previous = temp;
temp = temp->next_lightpath;
}
next = temp->next_lightpath;
//delete the current node from the linked list
if(previous == NULL){
if(next == NULL){
free(temp->route);
free(temp->edges);
free(temp);
temp = NULL;
existing_lightpath_list = NULL;
}
else {
existing_lightpath_list = next;
temp->next_lightpath = NULL;
free(temp->route);
free(temp->edges);
free(temp);
}
}
else{
if(next == NULL){
previous->next_lightpath = NULL;
for(i=0; i<nodes && temp->route[i] != -1; i++)
printf("%d ", temp->route[i]);
free(temp->route);
free(temp->edges);
free(temp);
}
else{
previous->next_lightpath = next;
temp->next_lightpath = NULL;
free(temp->route);
free(temp->edges);
free(temp);
}
}
the error detected with the 3rd case: free(temp->route) when previous is not NULL but next is NULL after the printing. I'm allocating mem for linked list nodes elsewhere in the program, nothing wrong with it Thanks in advance for any help