mirror of
https://github.com/jtheoof/swappy.git
synced 2024-09-11 14:55:49 +03:00
fix(pixbuf): handle invalid input file
If the input file is invalid (example: `grim` did not work due to invalid geometry), handle the error gracefully. Previously we had a coredump due to `g_error`.
This commit is contained in:
parent
a4429e8b7b
commit
cdbd06d7af
@ -10,3 +10,4 @@ void pixbuf_save_to_file(GdkPixbuf *pixbuf, char *file);
|
|||||||
void pixbuf_save_to_stdout(GdkPixbuf *pixbuf);
|
void pixbuf_save_to_stdout(GdkPixbuf *pixbuf);
|
||||||
void pixbuf_scale_surface_from_widget(struct swappy_state *state,
|
void pixbuf_scale_surface_from_widget(struct swappy_state *state,
|
||||||
GtkWidget *widget);
|
GtkWidget *widget);
|
||||||
|
void pixbuf_free(struct swappy_state *state);
|
||||||
|
@ -256,6 +256,7 @@ void blur_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
|
|||||||
|
|
||||||
void application_finish(struct swappy_state *state) {
|
void application_finish(struct swappy_state *state) {
|
||||||
paint_free_all(state);
|
paint_free_all(state);
|
||||||
|
pixbuf_free(state);
|
||||||
cairo_surface_destroy(state->rendering_surface);
|
cairo_surface_destroy(state->rendering_surface);
|
||||||
cairo_surface_destroy(state->original_image_surface);
|
cairo_surface_destroy(state->original_image_surface);
|
||||||
if (state->temp_file_str) {
|
if (state->temp_file_str) {
|
||||||
@ -269,7 +270,7 @@ void application_finish(struct swappy_state *state) {
|
|||||||
g_free(state->geometry);
|
g_free(state->geometry);
|
||||||
g_free(state->window);
|
g_free(state->window);
|
||||||
g_free(state->ui);
|
g_free(state->ui);
|
||||||
g_object_unref(state->original_image);
|
|
||||||
g_object_unref(state->app);
|
g_object_unref(state->app);
|
||||||
|
|
||||||
config_free(state);
|
config_free(state);
|
||||||
|
@ -70,7 +70,8 @@ GdkPixbuf *pixbuf_init_from_file(struct swappy_state *state) {
|
|||||||
GdkPixbuf *image = gdk_pixbuf_new_from_file(file, &error);
|
GdkPixbuf *image = gdk_pixbuf_new_from_file(file, &error);
|
||||||
|
|
||||||
if (error != NULL) {
|
if (error != NULL) {
|
||||||
g_error("unable to load file: %s - reason: %s", file, error->message);
|
g_printerr("unable to load file: %s - reason: %s\n", file, error->message);
|
||||||
|
g_error_free(error);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,3 +137,9 @@ finish:
|
|||||||
|
|
||||||
g_free(alloc);
|
g_free(alloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pixbuf_free(struct swappy_state *state) {
|
||||||
|
if (G_IS_OBJECT(state->original_image)) {
|
||||||
|
g_object_unref(state->original_image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user