Avoid g_error_free

Rely on g_autoptr() instead. This avoids having to free the
error.
This commit is contained in:
Guido Günther 2021-11-16 14:41:40 +01:00 committed by Martijn Braam
parent 6075ce1335
commit 69df649080
No known key found for this signature in database
GPG Key ID: C4280ACB000B060F
3 changed files with 7 additions and 14 deletions

View File

@ -55,12 +55,11 @@ static int dbus_old_brightness = 0;
static void static void
dbus_brightness_init(GObject *src, GAsyncResult *res, gpointer *user_data) dbus_brightness_init(GObject *src, GAsyncResult *res, gpointer *user_data)
{ {
GError *err = NULL; g_autoptr(GError) err = NULL;
dbus_brightness_proxy = g_dbus_proxy_new_finish(res, &err); dbus_brightness_proxy = g_dbus_proxy_new_finish(res, &err);
if (!dbus_brightness_proxy || err) { if (!dbus_brightness_proxy || err) {
printf("Failed to connect to dbus brightness service %s\n", printf("Failed to connect to dbus brightness service %s\n",
err->message); err->message);
g_error_free(err);
return; return;
} }
} }
@ -140,12 +139,11 @@ set_display_brightness(int brightness)
static void static void
brightness_received(GDBusProxy *proxy, GAsyncResult *res, gpointer user_data) brightness_received(GDBusProxy *proxy, GAsyncResult *res, gpointer user_data)
{ {
GError *error = NULL; g_autoptr(GError) error = NULL;
GVariant *result = g_dbus_proxy_call_finish(proxy, res, &error); GVariant *result = g_dbus_proxy_call_finish(proxy, res, &error);
if (!result) { if (!result) {
printf("Failed to get display brightness: %s\n", error->message); printf("Failed to get display brightness: %s\n", error->message);
g_error_free(error);
return; return;
} }

View File

@ -490,7 +490,7 @@ void
run_open_last_action(GSimpleAction *action, GVariant *param, gpointer user_data) run_open_last_action(GSimpleAction *action, GVariant *param, gpointer user_data)
{ {
char uri[275]; char uri[275];
GError *error = NULL; g_autoptr(GError) error = NULL;
if (strlen(last_path) == 0) { if (strlen(last_path) == 0) {
return; return;
@ -500,7 +500,6 @@ run_open_last_action(GSimpleAction *action, GVariant *param, gpointer user_data)
g_printerr("Could not launch image viewer for '%s': %s\n", g_printerr("Could not launch image viewer for '%s': %s\n",
uri, uri,
error->message); error->message);
g_error_free(error);
} }
} }
@ -508,11 +507,10 @@ void
run_open_photos_action(GSimpleAction *action, GVariant *param, gpointer user_data) run_open_photos_action(GSimpleAction *action, GVariant *param, gpointer user_data)
{ {
char uri[270]; char uri[270];
GError *error = NULL; g_autoptr(GError) error = NULL;
sprintf(uri, "file://%s", g_get_user_special_dir(G_USER_DIRECTORY_PICTURES)); sprintf(uri, "file://%s", g_get_user_special_dir(G_USER_DIRECTORY_PICTURES));
if (!g_app_info_launch_default_for_uri(uri, NULL, &error)) { if (!g_app_info_launch_default_for_uri(uri, NULL, &error)) {
g_printerr("Could not launch image viewer: %s\n", error->message); g_printerr("Could not launch image viewer: %s\n", error->message);
g_error_free(error);
} }
} }
@ -573,13 +571,12 @@ check_point_inside_bounds(int x, int y, int *bounds_x, int *bounds_y)
static void static void
on_zbar_dialog_response(GtkDialog *dialog, int response, char *data) on_zbar_dialog_response(GtkDialog *dialog, int response, char *data)
{ {
GError *error = NULL; g_autoptr(GError) error = NULL;
switch (response) { switch (response) {
case GTK_RESPONSE_YES: case GTK_RESPONSE_YES:
if (!g_app_info_launch_default_for_uri(data, NULL, &error)) { if (!g_app_info_launch_default_for_uri(data, NULL, &error)) {
g_printerr("Could not launch application: %s\n", g_printerr("Could not launch application: %s\n",
error->message); error->message);
g_error_free(error);
} }
case GTK_RESPONSE_ACCEPT: { case GTK_RESPONSE_ACCEPT: {
GdkDisplay *display = gtk_widget_get_display(GTK_WIDGET(dialog)); GdkDisplay *display = gtk_widget_get_display(GTK_WIDGET(dialog));
@ -925,12 +922,11 @@ update_ui_rotation()
static void static void
display_config_received(GDBusConnection *conn, GAsyncResult *res, gpointer user_data) display_config_received(GDBusConnection *conn, GAsyncResult *res, gpointer user_data)
{ {
GError *error = NULL; g_autoptr(GError) error = NULL;
GVariant *result = g_dbus_connection_call_finish(conn, res, &error); GVariant *result = g_dbus_connection_call_finish(conn, res, &error);
if (!result) { if (!result) {
printf("Failed to get display configuration: %s\n", error->message); printf("Failed to get display configuration: %s\n", error->message);
g_error_free(error);
return; return;
} }

View File

@ -597,7 +597,7 @@ process_capture_burst(GdkTexture *thumb)
burst_dir, burst_dir,
capture_fname, capture_fname,
save_dng_s); save_dng_s);
GError *error = NULL; g_autoptr(GError) error = NULL;
GSubprocess *proc = g_subprocess_new(G_SUBPROCESS_FLAGS_STDOUT_PIPE, GSubprocess *proc = g_subprocess_new(G_SUBPROCESS_FLAGS_STDOUT_PIPE,
&error, &error,
processing_script, processing_script,
@ -609,7 +609,6 @@ process_capture_burst(GdkTexture *thumb)
if (!proc) { if (!proc) {
g_printerr("Failed to spawn postprocess process: %s\n", g_printerr("Failed to spawn postprocess process: %s\n",
error->message); error->message);
g_error_free(error);
return; return;
} }