Fix minor valgrind issues

- Fix valgrind invalid write of 1 byte.
- Fix a few plugin related memory leaks.
This commit is contained in:
Jan Vidar Krey
2011-12-01 13:37:07 +01:00
parent c17b43e77f
commit 9f16298688
4 changed files with 15 additions and 1 deletions

View File

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

View File

@@ -30,6 +30,7 @@ struct uhub_plugin
{
void* handle;
plugin_unregister_f unregister;
char* filename;
};
struct uhub_plugins