[Initng-svn] r2396 - initng/src
svn at initng.thinktux.net
svn at initng.thinktux.net
Mon Dec 12 23:24:06 CET 2005
Author: jimmy
Date: Mon Dec 12 23:24:05 2005
New Revision: 2396
Modified:
initng/src/initng_load_module.c
initng/src/initng_load_module.h
Log:
Some cleanups to initng_load_module.c
Modified: initng/src/initng_load_module.c
==============================================================================
--- initng/src/initng_load_module.c (original)
+++ initng/src/initng_load_module.c Mon Dec 12 23:24:05 2005
@@ -196,9 +196,8 @@
if (m->module_init == NULL)
{
errmsg = dlerror();
- dlclose(m->module_dlhandle);
F_("Error reading module_init(); %s\n", errmsg);
- free(m);
+ close_and_free_module(m);
return (NULL);
}
@@ -208,9 +207,8 @@
if (m->module_unload == NULL)
{
errmsg = dlerror();
- dlclose(m->module_dlhandle);
F_("Error reading module_unload(); %s\n", errmsg);
- free(m);
+ close_and_free_module(m);
return (NULL);
}
@@ -229,13 +227,26 @@
/*
* Close the module.
*/
-void close_module(m_h * m)
+void close_and_free_module(m_h * m)
{
assert(m != NULL);
- dlclose(m->module_dlhandle);
- free(m->module_name);
- m->module_name = NULL;
+ /* free module name */
+ if(m->module_name)
+ {
+ free(m->module_name);
+ m->module_name = NULL;
+ }
+
+ /* close the lib */
+ if(m->module_dlhandle)
+ dlclose(m->module_dlhandle);
+
+ /* remove from list if added */
+ list_del(&m->list);
+
+ /* free struct */
+ free(m);
}
/* load a dynamic module */
@@ -281,8 +292,7 @@
{
F_("Not loading module \"%s\", missing needed module(s)\n",
module_path);
- close_module(new_m);
- free(new_m);
+ close_and_free_module(new_m);
return (NULL);
}
@@ -297,8 +307,7 @@
module_path, new_m->initziated);
/* XXX: used to be here, but why? */
/* sleep(1); */
- close_module(new_m);
- free(new_m);
+ close_and_free_module(new_m);
return (NULL);
}
@@ -351,11 +360,11 @@
{
assert(module != NULL);
+ /* run the unload hook */
(*module->module_unload) ();
- close_module(module);
-
- list_del(&module->list);
- free(module);
+
+ /* close and free the module entry in db */
+ close_and_free_module(module);
}
/* XXX: more information! */
@@ -435,11 +444,16 @@
current = open_module(module_path, module_name);
/* add this to the list of loaded modules */
- if (current)
- {
- assert(current->module_name);
- list_add(¤t->list, &g.module_db.list);
- }
+ if (!current)
+ {
+ free(module_name);
+ module_name=NULL;
+ continue;
+ }
+
+ /* add to list and continue */
+ assert(current->module_name);
+ list_add(¤t->list, &g.module_db.list);
}
else
{
@@ -464,9 +478,7 @@
if (!module_needs_are_loaded(current))
{
- close_module(current);
- list_del(¤t->list);
- free(current);
+ close_and_free_module(current);
continue;
}
@@ -479,9 +491,7 @@
if (current->initziated != TRUE)
{
F_("Module %s did not load correctly (module_init() returned %i)\n", current->module_name, current->initziated);
- close_module(current);
- list_del(¤t->list);
- free(current);
+ close_and_free_module(current);
}
}
Modified: initng/src/initng_load_module.h
==============================================================================
--- initng/src/initng_load_module.h (original)
+++ initng/src/initng_load_module.h Mon Dec 12 23:24:05 2005
@@ -34,6 +34,6 @@
/* functions for internal use only (exposed for testing) */
m_h *open_module(const char *module_path, const char *module_name);
-void close_module(m_h * m);
+void close_and_free_module(m_h * m);
#endif
More information about the Initng-svn
mailing list