gpt4 book ai didi

c - dlclose() 损坏的双链表 :

转载 作者:行者123 更新时间:2023-11-30 20:26:55 24 4
gpt4 key购买 nike

我正在使用基本的 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;
}

这是调用它的函数(包含共享库路径的 libtab):

#include "loadlib.h"
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>

void loadlib(char** libtab, Node** bst)
{
int i=0;
void* (*mime_type) ();
void* handle;
while(libtab[i]!=NULL)
{
handle=dlopen(libtab[i],RTLD_LAZY);
if(handle==NULL)
fprintf(stderr,"%s\n",dlerror());
else
{
mime_type=dlsym(handle,"getPlugins");
fill_tree(bst,mime_type());
}
++i;
/*dlclose(handle);*/
}
}

此代码仅使用一次循环迭代进行了测试,并且该函数本身正确地完成了其工作。当运行所有 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!

有人可以翻译这个错误的含义以及我做错了什么吗?

最佳答案

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

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

关于c - dlclose() 损坏的双链表 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23554518/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com