summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2008-03-25 13:11:42 +0000
committerLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2008-03-25 13:11:42 +0000
commit0d34aea6ba9d77a06b8d7a80550c63287b0bbd60 (patch)
tree82c1679cf362abd98da2410bf98b6881a6aa8552
parentcbace5633e81298844f4223ca1ca1c5d767dde5b (diff)
Fix possible memory leak on plugin failure and make plugin_init fail if the configured directory is invalid.
-rw-r--r--hcid/plugin.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/hcid/plugin.c b/hcid/plugin.c
index 46046116..1293e70f 100644
--- a/hcid/plugin.c
+++ b/hcid/plugin.c
@@ -60,50 +60,50 @@ gboolean plugin_init(void)
{
GDir *dir;
const gchar *file;
- gchar *filename;
- debug("Loading plugins");
+ debug("Loading plugins %s", PLUGINDIR);
dir = g_dir_open(PLUGINDIR, 0, NULL);
- if (dir != NULL) {
- while ((file = g_dir_read_name(dir)) != NULL) {
- GModule *module;
- struct bluetooth_plugin_desc *desc;
-
- if (g_str_has_prefix(file, "lib") == FALSE)
- continue;
+ if (!dir)
+ return FALSE;
- filename = g_build_filename(PLUGINDIR, file, NULL);
+ while ((file = g_dir_read_name(dir)) != NULL) {
+ GModule *module;
+ struct bluetooth_plugin_desc *desc;
+ gchar *filename;
- module = g_module_open(filename, 0);
- if (module == NULL) {
- error("Can't load plugin %s", filename);
- continue;
- }
+ if (g_str_has_prefix(file, "lib") == FALSE)
+ continue;
- g_free(filename);
+ filename = g_build_filename(PLUGINDIR, file, NULL);
- debug("%s", g_module_name(module));
+ module = g_module_open(filename, 0);
+ g_free(filename);
+ if (module == NULL) {
+ error("Can't load plugin %s", filename);
+ continue;
+ }
- if (g_module_symbol(module, "bluetooth_plugin_desc",
- (gpointer) &desc) == FALSE) {
- error("Can't load plugin description");
- g_module_close(module);
- continue;
- }
+ debug("%s", g_module_name(module));
- if (desc == NULL || desc->init == NULL) {
- g_module_close(module);
- continue;
- }
+ if (g_module_symbol(module, "bluetooth_plugin_desc",
+ (gpointer) &desc) == FALSE) {
+ error("Can't load plugin description");
+ g_module_close(module);
+ continue;
+ }
- if (add_plugin(module, desc) == FALSE)
- g_module_close(module);
+ if (desc == NULL || desc->init == NULL) {
+ g_module_close(module);
+ continue;
}
- g_dir_close(dir);
+ if (add_plugin(module, desc) == FALSE)
+ g_module_close(module);
}
+ g_dir_close(dir);
+
return TRUE;
}