diff options
author | Daniel Friesel <derf@finalrewind.org> | 2011-08-31 16:51:58 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2011-08-31 16:58:11 +0200 |
commit | 8b79bc33f37db12cbb672bdb47dcfeb0f2030bce (patch) | |
tree | 7fe42adc6685cdc4da86cad0e24a47ce035e1290 | |
parent | 232302e9b8e81fe7c712d3659164dea3d007b0fe (diff) |
feh_reload_image: Always die if reload failed
This fixes a segfault in --reload when the image becomes unloadable while feh
is running.
Note that this does not affect --reload with more than one file: If the
current image is removed, feh will simply jump to the next image. feh will
only quit if the file still exists, but can no longer be loaded.
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | src/events.c | 2 | ||||
-rw-r--r-- | src/feh.h | 2 | ||||
-rw-r--r-- | src/imlib.c | 4 | ||||
-rw-r--r-- | src/keyevents.c | 6 | ||||
-rw-r--r-- | src/menu.c | 2 | ||||
-rw-r--r-- | src/signals.c | 2 | ||||
-rw-r--r-- | src/slideshow.c | 22 | ||||
-rw-r--r-- | src/thumbnail.c | 2 |
9 files changed, 17 insertions, 26 deletions
@@ -9,6 +9,7 @@ git HEAD * The --filelist option now supports /dev/stdin (or "-" as shortcut) * Several Xinerama fixes, only --fullscreen on screen != 0 is still broken <https://github.com/derf/feh/issues/5> + * Fix segfault when trying to reload an image which is no longer loadable Tue, 16 Aug 2011 22:48:06 +0200 Daniel Friesel <derf@finalrewind.org> diff --git a/src/events.c b/src/events.c index 96408e1..68f8c11 100644 --- a/src/events.c +++ b/src/events.c @@ -127,7 +127,7 @@ static void feh_event_handle_ButtonPress(XEvent * ev) } else if (ev->xbutton.button == opt.reload_button) { D(("Reload Button Press event\n")); if (winwid != NULL) - feh_reload_image(winwid, 0, 0); + feh_reload_image(winwid, 0); } else if (ev->xbutton.button == opt.prev_button) { D(("Prev Button Press event\n")); if ((winwid != NULL) @@ -146,7 +146,7 @@ void feh_draw_info(winwidget w); void feh_draw_errstr(winwidget w); void feh_display_status(char stat); void real_loadables_mode(int loadable); -void feh_reload_image(winwidget w, int resize, int force_new); +void feh_reload_image(winwidget w, int resize); void feh_filelist_image_remove(winwidget winwid, char do_delete); void slideshow_save_image(winwidget win); void feh_edit_inplace(winwidget w, int orientation); diff --git a/src/imlib.c b/src/imlib.c index 47031bd..ed3fc12 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -801,7 +801,7 @@ void feh_edit_inplace(winwidget w, int op) if (!strcmp(gib_imlib_image_format(w->im), "jpeg")) { feh_edit_inplace_lossless(w, op); - feh_reload_image(w, 1, 1); + feh_reload_image(w, 1); return; } @@ -817,7 +817,7 @@ void feh_edit_inplace(winwidget w, int op) gib_imlib_image_orientate(old, op); gib_imlib_save_image(old, FEH_FILE(w->file->data)->filename); gib_imlib_free_image(old); - feh_reload_image(w, 1, 1); + feh_reload_image(w, 1); } else { im_weprintf(w, "failed to load image from disk to edit it in place"); } diff --git a/src/keyevents.c b/src/keyevents.c index 60663db..8e6e3f6 100644 --- a/src/keyevents.c +++ b/src/keyevents.c @@ -333,7 +333,7 @@ void feh_event_invoke_action(winwidget winwid, unsigned char action) feh_action_run(FEH_FILE(winwid->file->data), opt.actions[action]); if (opt.hold_actions[action]) - feh_reload_image(winwid, 1, 1); + feh_reload_image(winwid, 1); else slideshow_change_image(winwid, SLIDE_NEXT, 1); @@ -342,7 +342,7 @@ void feh_event_invoke_action(winwidget winwid, unsigned char action) feh_action_run(FEH_FILE(winwid->file->data), opt.actions[action]); if (opt.hold_actions[action]) - feh_reload_image(winwid, 1, 1); + feh_reload_image(winwid, 1); else winwidget_destroy(winwid); } else if (winwid->type == WIN_TYPE_THUMBNAIL) @@ -630,7 +630,7 @@ void feh_event_handle_keypress(XEvent * ev) winwidget_render_image(winwid, 0, 0); } else if (feh_is_kp(&keys.reload_image, keysym, state)) { - feh_reload_image(winwid, 0, 0); + feh_reload_image(winwid, 0); } else if (feh_is_kp(&keys.toggle_pause, keysym, state)) { slideshow_pause_toggle(winwid); @@ -1302,7 +1302,7 @@ void feh_menu_cb(feh_menu * m, feh_menu_item * i, int action, void *data) winwidget_render_image(m->fehwin, 1, 0); break; case CB_RELOAD: - feh_reload_image(m->fehwin, 0, 0); + feh_reload_image(m->fehwin, 0); break; case CB_REMOVE: feh_filelist_image_remove(m->fehwin, 0); diff --git a/src/signals.c b/src/signals.c index d5a6899..01cdf72 100644 --- a/src/signals.c +++ b/src/signals.c @@ -70,7 +70,7 @@ void feh_handle_signal(int signo) slideshow_change_image(winwid, SLIDE_PREV, 1); } else if (opt.multiwindow) { for (i = window_num - 1; i >= 0; i--) - feh_reload_image(windows[i], 0, 0); + feh_reload_image(windows[i], 0); } return; diff --git a/src/slideshow.c b/src/slideshow.c index ba9e028..22d2124 100644 --- a/src/slideshow.c +++ b/src/slideshow.c @@ -135,12 +135,12 @@ void cb_reload_timer(void *data) winwidget_rename(w, current_filename); free(current_filename); - feh_reload_image(w, 1, 0); + feh_reload_image(w, 1); feh_add_unique_timer(cb_reload_timer, w, opt.reload); return; } -void feh_reload_image(winwidget w, int resize, int force_new) +void feh_reload_image(winwidget w, int resize) { char *title, *new_title; int len; @@ -152,7 +152,7 @@ void feh_reload_image(winwidget w, int resize, int force_new) return; } - D(("resize %d, force_new %d\n", resize, force_new)); + D(("resize %d\n", resize)); free(FEH_FILE(w->file->data)->caption); FEH_FILE(w->file->data)->caption = NULL; @@ -169,20 +169,10 @@ void feh_reload_image(winwidget w, int resize, int force_new) /* force imlib2 not to cache */ winwidget_free_image(w); - /* if the image has changed in dimensions - we gotta resize */ - if ((feh_load_image(&tmp, FEH_FILE(w->file->data))) == 0) { - if (force_new) { - eprintf("failed to reload image\n"); - } else { - im_weprintf(w, "Couldn't reload image. Is it still there?"); - } - winwidget_rename(w, title); - free(title); - free(new_title); - filelist = feh_file_remove_from_list(filelist, w->file); - return; - } + if ((feh_load_image(&tmp, FEH_FILE(w->file->data))) == 0) + eprintf("failed to reload image"); + /* if the image has changed in dimensions - we gotta resize */ if (!resize && ((old_w != gib_imlib_image_get_width(tmp)) || (old_h != gib_imlib_image_get_height(tmp)))) resize = 1; diff --git a/src/thumbnail.c b/src/thumbnail.c index ee8b101..9053649 100644 --- a/src/thumbnail.c +++ b/src/thumbnail.c @@ -922,7 +922,7 @@ void feh_thumbnail_show_fullsize(feh_file *thumbfile) free(thumbwin->file); thumbwin->file = gib_list_add_front(NULL, thumbfile); winwidget_rename(thumbwin, s); - feh_reload_image(thumbwin, 1, 0); + feh_reload_image(thumbwin, 1); } } |