dlclose()已损坏的双链接列表:

dlclose()已损坏的双链接列表:,c,shared-libraries,C,Shared Libraries,我正在使用一个基本的C插件系统dlclose()。这是我的密码: #include <stdlib.h> #include <string.h> char** getPlugins() { int i; char** tab=malloc(sizeof(char*)*5); for(i=0;i<6;++i) tab[i]=malloc(sizeof(char)*10); strcpy(tab[0],"plugin1

我正在使用一个基本的C插件系统
dlclose()
。这是我的密码:

#include <stdlib.h>
#include <string.h>

char** getPlugins()
{
    int i;
    char** tab=malloc(sizeof(char*)*5);
    for(i=0;i<6;++i)
        tab[i]=malloc(sizeof(char)*10);

    strcpy(tab[0],"plugin1");
    strcpy(tab[1],"plugin2");
    strcpy(tab[2],"plugin3");
    strcpy(tab[3],"plugin4");
    tab[4]=NULL;
    return tab;
}

有人能解释这个错误的意思和我做错了什么吗?

你循环太远了,分配了5个指针,循环到6个:

char** tab=malloc(sizeof(char*)*5);
for(i=0;i<6;++i)
    tab[i]=malloc(sizeof(char)*10);
char**tab=malloc(sizeof(char*)*5);

对于(i=0;i您分配了5个指针,但循环了0-5个指针(包括6个项目)。非常感谢。事实上就是这样。这个奇怪的错误实际上让我感到很难受,因为它看起来更微妙。
*** Error in `./plugin': corrupted double-linked list: 0x0000000000e6aad0 ***
Inconsistency detected by ld.so: dl-open.c: 220: dl_open_worker: Assertion `_dl_debug_initialize (0, args->nsid)->r_state == RT_CONSISTENT' failed!
char** tab=malloc(sizeof(char*)*5);
for(i=0;i<6;++i)
    tab[i]=malloc(sizeof(char)*10);