Fix GError handling

Several users have reported segfaults when starting up profanity which
has OMEMO support, but OMEMO is not set up yet.

@StefanKropp has been able to reproduce this and tracked it down to
`_load_identity()` calling `omemo_known_devices_keyfile_save()`.
The latter then calls `save_keyfile()` which calls
`g_key_file_save_to_file()`. This can then fail if one of the first two
strings is NULL and won't set the `error` on return. In its error handling
`save_keyfile()` unconditionally dereferences `error` which leads to the
segfault.

Fix this and also go through the entire codebase and verify that the usage
of `GError` is done correctly.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
Steffen Jaeckel
2025-10-09 10:23:00 +02:00
parent 5da079bbb2
commit 48ac88de08
15 changed files with 57 additions and 66 deletions

View File

@@ -97,14 +97,13 @@ _notify(const char* const message, int timeout, const char* const category)
notify_notification_set_category(notification, category);
notify_notification_set_urgency(notification, NOTIFY_URGENCY_NORMAL);
GError* error = NULL;
auto_gerror GError* error = NULL;
gboolean notify_success = notify_notification_show(notification, &error);
if (!notify_success) {
log_error("Error sending desktop notification:");
log_error(" -> Message : %s", message);
log_error(" -> Error : %s", error->message);
g_error_free(error);
log_error(" -> Error : %s", PROF_GERROR_MESSAGE(error));
} else {
log_debug("Notification sent.");
}

View File

@@ -81,7 +81,7 @@ _get_icons(void)
auto_gchar gchar* icons_dir_s = files_get_config_path(DIR_ICONS);
icons_dir = g_string_new(icons_dir_s);
GError* err = NULL;
auto_gerror GError* err = NULL;
if (!g_file_test(icons_dir->str, G_FILE_TEST_IS_DIR)) {
return;
@@ -109,8 +109,7 @@ _get_icons(void)
}
g_string_free(name, TRUE);
} else {
log_error("Unable to open dir: %s", err->message);
g_error_free(err);
log_error("Unable to open dir: %s", PROF_GERROR_MESSAGE(err));
}
g_dir_close(dir);
g_string_free(icons_dir, TRUE);