From 9f162986888a6d1cd5609068aba4c55ed205169d Mon Sep 17 00:00:00 2001 From: Jan Vidar Krey Date: Thu, 1 Dec 2011 13:37:07 +0100 Subject: [PATCH] Fix minor valgrind issues - Fix valgrind invalid write of 1 byte. - Fix a few plugin related memory leaks. --- src/core/pluginloader.c | 9 +++++++++ src/core/pluginloader.h | 1 + src/plugins/mod_logging.c | 2 ++ src/util/config_token.c | 4 +++- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core/pluginloader.c b/src/core/pluginloader.c index cb0b016..cf4036c 100644 --- a/src/core/pluginloader.c +++ b/src/core/pluginloader.c @@ -50,16 +50,19 @@ struct uhub_plugin* plugin_open(const char* filename) return 0; } + plugin->filename = strdup(filename); return plugin; } void plugin_close(struct uhub_plugin* plugin) { + LOG_TRACE("plugin_close: \"%s\"", plugin->filename); #ifdef HAVE_DLOPEN dlclose(plugin->handle); #else FreeLibrary((HMODULE) plugin->handle); #endif + hub_free(plugin->filename); hub_free(plugin); } @@ -127,6 +130,7 @@ void plugin_unload(struct plugin_handle* plugin) { plugin->handle->unregister(plugin); plugin_close(plugin->handle); + hub_free(plugin); } static int plugin_parse_line(char* line, int line_count, void* ptr_data) @@ -186,7 +190,12 @@ int plugin_initialize(struct hub_config* config, struct uhub_plugins* handle) ret = file_read_lines(config->file_plugins, handle, &plugin_parse_line); if (ret == -1) + { + list_clear(handle->loaded, hub_free); + list_destroy(handle->loaded); + handle->loaded = 0; return -1; + } } return 0; } diff --git a/src/core/pluginloader.h b/src/core/pluginloader.h index 33b5cc4..2d32e76 100644 --- a/src/core/pluginloader.h +++ b/src/core/pluginloader.h @@ -30,6 +30,7 @@ struct uhub_plugin { void* handle; plugin_unregister_f unregister; + char* filename; }; struct uhub_plugins diff --git a/src/plugins/mod_logging.c b/src/plugins/mod_logging.c index 2147c81..4b3a786 100644 --- a/src/plugins/mod_logging.c +++ b/src/plugins/mod_logging.c @@ -100,6 +100,8 @@ static struct log_data* parse_config(const char* line, struct plugin_handle* plu token = cfg_token_get_next(tokens); } + cfg_tokens_free(tokens); + if (data->logmode == mode_file) { if ((data->logmode == mode_file && !data->logfile)) diff --git a/src/util/config_token.c b/src/util/config_token.c index fefc5bd..d958dd6 100644 --- a/src/util/config_token.c +++ b/src/util/config_token.c @@ -30,7 +30,7 @@ struct cfg_tokens struct cfg_tokens* cfg_tokenize(const char* line) { struct cfg_tokens* tokens = (struct cfg_tokens*) hub_malloc_zero(sizeof(struct cfg_tokens)); - char* buffer = (char*) hub_malloc_zero(strlen(line)); + char* buffer = (char*) hub_malloc_zero(strlen(line) + 1); char* out = buffer; const char* p = line; int backslash = 0; @@ -68,6 +68,7 @@ struct cfg_tokens* cfg_tokenize(const char* line) else { RESET_TOKEN; + hub_free(buffer); return tokens; } break; @@ -115,6 +116,7 @@ struct cfg_tokens* cfg_tokenize(const char* line) } RESET_TOKEN; + hub_free(buffer); return tokens; }