Fix a crash/bug rasing when read_next_module_name() current module is unload before next call.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4700 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin 2003-09-16 00:56:37 +00:00
parent 0f8efd8af0
commit d07d632d7f

View File

@ -48,6 +48,7 @@ typedef struct module_addon {
char * path;
image_id addon_image; // if -1, not loaded in memory currently
module_info ** infos; // valid only when addon_image != -1
int32 enumerators;
} module_addon;
typedef struct module_list_cookie {
@ -210,6 +211,7 @@ _EXPORT void * open_module_list(const char *prefix)
mlc->search_paths = (addon_path ? strdup(addon_path) : NULL);
mlc->search_path = strtok_r(mlc->search_paths, ":", &mlc->next_path_token);
mlc->dir_stack = new BList();
mlc->ma = NULL;
mlc->mi = NULL;
@ -253,6 +255,7 @@ _EXPORT status_t read_next_module_name(void *cookie, char *buf, size_t *bufsize)
};
// We've iterate all module names of this module addon. Find another one...
atomic_add(&mlc->ma->enumerators, -1);
unload_module_addon(mlc->ma);
mlc->ma = NULL;
mlc->mi = NULL;
@ -317,6 +320,7 @@ _EXPORT status_t read_next_module_name(void *cookie, char *buf, size_t *bufsize)
// WTF it's doing there?!?
continue;
atomic_add(&mlc->ma->enumerators, 1);
// call ourself to enter the module names list iteration at
// function begining code...
mlc->mi = mlc->ma->infos;
@ -349,8 +353,10 @@ _EXPORT status_t close_module_list(void *cookie)
ASSERT(mlc);
ASSERT(mlc->prefix);
if (mlc->ma)
if (mlc->ma) {
atomic_add(&mlc->ma->enumerators, -1);
unload_module_addon(mlc->ma);
};
while((dir = (BDirectory *) mlc->dir_stack->FirstItem())) {
mlc->dir_stack->RemoveItem(dir);
@ -361,7 +367,7 @@ _EXPORT status_t close_module_list(void *cookie)
free(mlc->search_paths);
free(mlc->prefix);
free(mlc);
// free(mlc);
return B_ERROR;
}
@ -449,6 +455,7 @@ static module_addon * load_module_addon(const char * path)
LOCK_MODULES;
ma->ref_count = 0;
ma->enumerators = 0;
ma->keep_loaded = false;
ma->path = strdup(path);
ma->addon_image = addon_id;
@ -539,6 +546,9 @@ static status_t unload_module_addon(module_addon * ma)
// built-in modules are addon-less, so nothing to do...
return B_OK;
if (ma->enumerators)
return B_OK;
if (ma->keep_loaded) {
printf("B_KEEP_LOADED flag set for %s module addon. Will be *never* unloaded!\n",
ma->path);