qulogic/gplugin

Fix use-after-free found in tests by valgrind.
feature/fix-valgrind
2019-01-27, Elliott Sales de Andrade
28bc1a2271e0
Parents 4a07e289eef4
Children bac9853cb383
Fix use-after-free found in tests by valgrind.
--- a/gplugin/gplugin-manager.c Sun Jan 27 19:29:45 2019 -0500
+++ b/gplugin/gplugin-manager.c Sun Jan 27 20:18:22 2019 -0500
@@ -1228,8 +1228,7 @@
* Gets the list of paths which will be search for plugins.
*
* Return value: (element-type utf8) (transfer none): list of paths which will
- * be searched for plugins. free the list with g_list_free when
- * done.
+ * be searched for plugins.
*/
GList *
gplugin_manager_get_paths(void) {
--- a/gplugin/tests/dynamic-type/dynamic-type-user.c Sun Jan 27 19:29:45 2019 -0500
+++ b/gplugin/tests/dynamic-type/dynamic-type-user.c Sun Jan 27 20:18:22 2019 -0500
@@ -51,10 +51,14 @@
}
G_MODULE_EXPORT gboolean
-gplugin_unload(G_GNUC_UNUSED GPluginNativePlugin *plugin, GError **error) {
+gplugin_unload(G_GNUC_UNUSED GPluginNativePlugin *plugin, GError **error)
+{
+ gpointer weak_test_object = test_object;
+ g_object_add_weak_pointer(G_OBJECT(test_object), &weak_test_object);
+
g_object_unref(test_object);
- if (DYNAMIC_IS_TEST(test_object)) {
+ if (DYNAMIC_IS_TEST(weak_test_object)) {
g_set_error(error, GPLUGIN_DOMAIN, 0,
"test_object is still valid");
return FALSE;
--- a/gplugin/tests/test-plugin-manager-paths.c Sun Jan 27 19:29:45 2019 -0500
+++ b/gplugin/tests/test-plugin-manager-paths.c Sun Jan 27 20:18:22 2019 -0500
@@ -106,7 +106,6 @@
for(l = paths; l; l = l->next) {
g_hash_table_remove(req, l->data);
}
- g_list_free(paths);
size = g_hash_table_size(req);
@@ -142,7 +141,6 @@
paths = gplugin_manager_get_paths();
for(l = paths; l != NULL; l = l->next)
g_hash_table_remove(req, l->data);
- g_list_free(paths);
/* now check the hash table size, if it's > 0 then an expected path wasn't
* added.