gplugin/gplugin

Parents 6ca5852ebfe1
Children bdae2f4577c5
Add some additional error checking to gplugin_native_loader_query

Testing Done:
Ran the unit tests

Reviewed at https://reviews.imfreedom.org/r/1848/
--- a/gplugin/gplugin-native-loader.c Tue Sep 27 00:10:22 2022 -0500
+++ b/gplugin/gplugin-native-loader.c Tue Sep 27 00:11:07 2022 -0500
@@ -177,15 +177,27 @@
G_MODULE_BIND_LOCAL,
&query,
error);
+
+ /* If the query returned an error, clear any info it may have set and return
+ * NULL.
+ */
+ if(error != NULL && *error != NULL) {
+ g_clear_object(&info);
+
+ return NULL;
+ }
+
+ /* If we didn't get an info back, create a generic error. */
if(!GPLUGIN_IS_PLUGIN_INFO(info)) {
- if(error && *error == NULL) {
- g_set_error_literal(
- error,
- GPLUGIN_DOMAIN,
- 0,
- _("the query function did not return a "
- "GPluginPluginInfo instance"));
- }
+ /* Error was already checked earlier if it was non-null. */
+ g_set_error_literal(
+ error,
+ GPLUGIN_DOMAIN,
+ 0,
+ _("the query function did not return a "
+ "GPluginPluginInfo instance"));
+
+ g_clear_object(&info);
return NULL;
}
--- a/gplugin/tests/bad-plugins/query-error.c Tue Sep 27 00:10:22 2022 -0500
+++ b/gplugin/tests/bad-plugins/query-error.c Tue Sep 27 00:11:07 2022 -0500
@@ -19,7 +19,7 @@
#include <gplugin-native.h>
static GPluginPluginInfo *
-query_error_query(G_GNUC_UNUSED GError **error)
+query_error_query(GError **error)
{
g_set_error(error, GPLUGIN_DOMAIN, 0, "expected error");