glibc检测到*** ./out:双重免费或损坏(!prev):0x082a7dd0

时间:2013-09-06 09:26:36

标签: c

我在运行程序时遇到此错误 glibc检测到 * ./out:双重免费或损坏(!prev):0x082a7dd0 尝试释放指针时会出现问题,这里是代码的某些部分:

//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;
};

此代码用于从链表中删除节点

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);
    }
}

第三种情况检测到的错误:free(temp-&gt; route),当previous不是NULL但是next在打印后为NULL。我正在为程序中的其他地方的链表节点分配mem,没有任何问题 在此先感谢您的任何帮助

0 个答案:

没有答案