From bfea10205a9fd4cb02cd6c94d2d94baaefaed278 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 28 Aug 2020 22:46:58 +0200 Subject: Fix segmentation fault when combining --multiwindow and --reload Introduced in 3fa39154f089a6fadc1a14eb6b206e2d2875be71 --- src/slideshow.c | 79 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 36 deletions(-) diff --git a/src/slideshow.c b/src/slideshow.c index 03e8e06..07a1e94 100644 --- a/src/slideshow.c +++ b/src/slideshow.c @@ -135,47 +135,54 @@ void cb_reload_timer(void *data) winwidget w = (winwidget) data; - /* save the current filename for refinding it in new list */ - current_filename = estrdup(FEH_FILE(current_file->data)->filename); + /* + * multi-window mode has no concept of a "current file" and + * dynamically adding/removing windows is not implemented at the moment. + * So don't reload filelists in multi-window mode. + */ + if (current_file != NULL) { + /* save the current filename for refinding it in new list */ + current_filename = estrdup(FEH_FILE(current_file->data)->filename); - for (l = filelist; l; l = l->next) { - feh_file_free(l->data); - l->data = NULL; - } - gib_list_free_and_data(filelist); - filelist = NULL; - filelist_len = 0; - current_file = NULL; - - /* rebuild filelist from original_file_items */ - if (gib_list_length(original_file_items) > 0) - for (l = gib_list_last(original_file_items); l; l = l->prev) - add_file_to_filelist_recursively(l->data, FILELIST_FIRST); - else if (!opt.filelistfile && !opt.bgmode) - add_file_to_filelist_recursively(".", FILELIST_FIRST); - - if (opt.filelistfile) { - filelist = gib_list_cat(filelist, feh_read_filelist(opt.filelistfile)); - } - - if (!(filelist_len = gib_list_length(filelist))) { - eprintf("No files found to reload."); - } + for (l = filelist; l; l = l->next) { + feh_file_free(l->data); + l->data = NULL; + } + gib_list_free_and_data(filelist); + filelist = NULL; + filelist_len = 0; + current_file = NULL; + + /* rebuild filelist from original_file_items */ + if (gib_list_length(original_file_items) > 0) + for (l = gib_list_last(original_file_items); l; l = l->prev) + add_file_to_filelist_recursively(l->data, FILELIST_FIRST); + else if (!opt.filelistfile && !opt.bgmode) + add_file_to_filelist_recursively(".", FILELIST_FIRST); + + if (opt.filelistfile) { + filelist = gib_list_cat(filelist, feh_read_filelist(opt.filelistfile)); + } + + if (!(filelist_len = gib_list_length(filelist))) { + eprintf("No files found to reload."); + } - feh_prepare_filelist(); + feh_prepare_filelist(); - /* find the previously current file */ - for (l = filelist; l; l = l->next) - if (strcmp(FEH_FILE(l->data)->filename, current_filename) == 0) { - current_file = l; - break; - } + /* find the previously current file */ + for (l = filelist; l; l = l->next) + if (strcmp(FEH_FILE(l->data)->filename, current_filename) == 0) { + current_file = l; + break; + } - free(current_filename); + free(current_filename); - if (!current_file) - current_file = filelist; - w->file = current_file; + if (!current_file) + current_file = filelist; + w->file = current_file; + } feh_reload_image(w, 1, 0); feh_add_unique_timer(cb_reload_timer, w, opt.reload); -- cgit v1.2.3