質問

I'm using a basic C plugin system dlclose(). Here is my code:

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

Here's the function calling it (libtab containing the shared library path):

#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);*/
    }
}

This code was tested with only one loop iteration, and the function itself does its job correctly. And when running all 6 items, I get an error:

*** 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!

Can someone translate what this error means and what I'm doing wrong?

役に立ちましたか?

解決

You're looping too far, allocating 5 pointers and looping until 6:

char** tab=malloc(sizeof(char*)*5);
for(i=0;i<6;++i)
    tab[i]=malloc(sizeof(char)*10);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top