* glibc检测到双重释放或损坏()*消息! [英] *glibc detected double free or corruption() * message!

查看:104
本文介绍了* glibc检测到双重释放或损坏()*消息!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行程序时,以下deleteNode函数将获得这些信息: * glibc检测到 free():下一个大小无效(正常):0x000000000103dd90 * *

The following deleteNode function when I run the program gets these: * glibc detected free(): invalid next size (normal): 0x000000000103dd90 **

即使我免费提供了(此处);发表评论,我收到以上消息. 我不认为其他免费"电话会引起这样的问题.但是我不明白为什么这是错误的. :/

Even i make the ' free(here); ' a comment,i get the above message. I dont think that the other 'free' calls provokes a problem like that. But I cant see why this would be wrong. :/

struct List *deleteNode(int Code,int i,char* Number)
    {
        struct List *here;
        here=Head;

        for (here; here!=Tail; here=here->next)
        {       
            if ( (here->number==Number) && (here->code==Code) )//found node on the List
            {
                if (here->previous==Head)        //delete from beginning
                {           
                    Head=here->next;
                    here->next->previous=Head;
                }
                else if (here->next==Tail) //delete from the end
                {
                    here->previous->next=Tail;
                    Tail=here->previous;
                }
                else  //delete from the middle of the list
                {   
                    here->previous->next=here->next;
                    here->next->previous=here->previous;
                }
                break;
            }
        }

        free (here);

    }

如果我使用得很好并且了解漫游,那么问题就出在我的主要功能上. 我也有一些免费",但在此消息之前我更改了deleteNode,所以我认为问题出在deleteNode函数上.

if i used and understand valgring well then the problem is on my main function. i have also there some 'free' but i changed deleteNode before this message so i thought that the problem was on the deleteNode function.

现在,没有free()的下一个尺寸无效....但是很遗憾,这是: glibc检测到 *:两次释放或损坏(出):0x00007fff1aae9ae0 * :(

Now,there is no free() invalid next size.... but unfortunately this: glibc detected * : double free or corruption (out): 0x00007fff1aae9ae0 * :(

主体的一部分:

FILE *File;
    if ( ( File=fopen("File.txt","r")) !=NULL )
    {                               
        int li = 0;    
        char *lin = (char *) malloc(MAX_LINE * sizeof(char));


        while(fgets(lin, MAX_LINE, eventFile) != NULL)
        {
            token = linetok(lin, " ");

            if(token != NULL)
            {

                int i,code,nodeID;
            char *number;
            char *event;

                for(i = 0; token[i] != NULL; i += 1)
                {
            code=atoi(token[0]);
            strcpy(event,token[1]);
            nodeID=atoi(token[2]);
            strcpy(number,token[3]) ;

            int i;
            if (!strcmp(event,"add"))
            {       
                add_to_List(code,i,number);
            }
            else if(!strcmp(event,"delete"))
            {       
                             deleteNode(eventNo,i,number);
                    }
            free(event);
            free(phoneNumber);  
        }
                free(token);
            }
            else 
            {
                printf("Error reading line %s\n", lin);
                exit(1);   
            }
        }
    } 
    else 
    {
        printf("Error opening file with the events.\nEXIT!");
        exit(0);
    }

对其进行调试...

main' pro:(.text+0xce0): first defined here /usr/lib/gcc/x86_64-linux-gnu/4.4.1/crtend.o:(.dtors+0x0): multiple definition of DTOR_END 的多个定义 pro :(.dtors + 0x8):首先在这里定义 /usr/bin/ld:警告:无法创建.eh_frame_hdr节,--eh-frame-hdr被忽略. /usr/bin/ld:pro1(.eh_frame)中的错误;不会创建任何.eh_frame_hdr表. collect2:ld返回1个退出状态

multiple definition of main' pro:(.text+0xce0): first defined here /usr/lib/gcc/x86_64-linux-gnu/4.4.1/crtend.o:(.dtors+0x0): multiple definition ofDTOR_END' pro:(.dtors+0x8): first defined here /usr/bin/ld: warning: Cannot create .eh_frame_hdr section, --eh-frame-hdr ignored. /usr/bin/ld: error in pro1(.eh_frame); no .eh_frame_hdr table will be created. collect2: ld returned 1 exit status

推荐答案

下一个大小无效"表示glibc已在您的内存区域检测到损坏.

"Invalid next size" means that glibc has detected corruption in your memory arena.

您已经覆盖了存储在分配的块之间的重要会计信息.

You have overwritten valuable accounting information that's stored in between your allocated blocks.

malloc为您提供的每个数据块中,附近都存储有一些会计信息.例如,当您通过将128个字符写入20个字符的缓冲区来覆盖此信息时,glibc可能会在您下次尝试释放(或可能分配)一些内存时检测到这一点.

With each block that malloc gives you, there is some accounting information stored close by. When you overwrite this information by, for example, writing 128 characters to a 20-character buffer, glibc may detect this the next time you try to free (or possibly allocate) some memory.

您需要找到此问题的根本原因-这不是免费的本身,而这正是检测到的地方.在某个地方,您的某些代码正在浪费内存,而像valgrind这样的内存分析工具将在这里发挥着不可估量的作用.

You need to find the root cause of this problem - it's not the free itself, that's just where the problem is being detected. Somewhere, some of your code is trashing memory and a memory analysis tool like valgrind will be invaluable here.

这篇关于* glibc检测到双重释放或损坏()*消息!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆