gplugin/gplugin

Fix a use-after-free when plugins fail to load.
feature/fix-valgrind
2019-01-27, Elliott Sales de Andrade
bac9853cb383
Fix a use-after-free when plugins fail to load.
--- a/gplugin/gplugin-native-loader.c Sun Jan 27 20:18:22 2019 -0500
+++ b/gplugin/gplugin-native-loader.c Sun Jan 27 20:43:14 2019 -0500
@@ -107,21 +107,27 @@
GPluginPluginInfo *info = NULL;
*module = gplugin_native_loader_open(filename, flags, error);
- if((*module == NULL) || (error && *error))
+ if (*module == NULL) {
return NULL;
+ } else if (error && *error) {
+ g_module_close(*module);
+ *module = NULL;
+ return NULL;
+ }
*query = gplugin_native_loader_lookup_symbol(*module, GPLUGIN_QUERY_SYMBOL,
error);
if((*query == NULL) || (error && *error)) {
g_module_close(*module);
+ *module = NULL;
return NULL;
}
info = ((GPluginNativePluginQueryFunc)(*query))(error);
if(error && *error) {
g_module_close(*module);
-
+ *module = NULL;
return NULL;
}
@@ -143,9 +149,6 @@
info = gplugin_native_loader_open_and_query(filename, &module, 0, &query,
error);
if(!GPLUGIN_IS_PLUGIN_INFO(info)) {
- if(module)
- g_module_close(module);
-
if (error && *error == NULL) {
g_set_error_literal(error, GPLUGIN_DOMAIN, 0,
_("the query function did not return a "
@@ -163,8 +166,6 @@
G_MODULE_BIND_LOCAL,
&query, error);
if(!GPLUGIN_IS_PLUGIN_INFO(info)) {
- g_module_close(module);
-
if (error && *error == NULL) {
g_set_error_literal(error, GPLUGIN_DOMAIN, 0,
_("the query function did not return a "