Skip to content

Commit

Permalink
Avoid a possible deadlock in the fix for 2.3.1
Browse files Browse the repository at this point in the history
pqiv used MagickWandTerminus as atexit(), but MagickWand is not
reentrant. Lock the mutex in the atexit() handler to prevent active
MagickWand methods in the loader thread from deadlocking.
  • Loading branch information
phillipberndt committed Mar 22, 2015
1 parent eed6e15 commit 67b551f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ Known bugs
Changelog
---------

pqiv 2.3.2
* Avoid a possible deadlock in the fix for 2.3.1

pqiv 2.3.1
* Properly handle if a user closes pqiv while the image loader is still active

Expand Down
8 changes: 7 additions & 1 deletion backends/wand.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ void file_type_wand_draw(file_t *file, cairo_t *cr) {/*{{{*/
}
}/*}}}*/

static void file_type_wand_exit_handler() {/*{{{*/
G_LOCK(magick_wand_global_lock);
MagickWandTerminus();
G_UNLOCK(magick_wand_global_lock);
}/*}}}*/

void file_type_wand_initializer(file_type_handler_t *info) {/*{{{*/
// Fill the file filter pattern
MagickWandGenesis();
Expand All @@ -298,7 +304,7 @@ void file_type_wand_initializer(file_type_handler_t *info) {/*{{{*/

// We need to register MagickWandTerminus(), imageMagick's exit handler, to
// cleanup temporary files when pqiv exits.
atexit(MagickWandTerminus);
atexit(file_type_wand_exit_handler);

// Magick Wand does not give us MIME types. Manually add the most interesting one:
gtk_file_filter_add_mime_type(info->file_types_handled, "image/vnd.adobe.photoshop");
Expand Down
8 changes: 5 additions & 3 deletions pqiv.c
Original file line number Diff line number Diff line change
Expand Up @@ -3765,9 +3765,11 @@ gpointer load_images_thread(gpointer user_data) {/*{{{*/

load_images(&global_argc, global_argv);

if(bostree_node_count(file_tree) == 0) {
g_printerr("No images left to display.\n");
exit(1);
if(file_tree_valid) {
if(bostree_node_count(file_tree) == 0) {
g_printerr("No images left to display.\n");
exit(1);
}
}

if(user_data != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion pqiv.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "lib/bostree.h"

#ifndef PQIV_VERSION
#define PQIV_VERSION "2.3.1"
#define PQIV_VERSION "2.3.2"
#endif

#define FILE_FLAGS_ANIMATION (guint)(1)
Expand Down

0 comments on commit 67b551f

Please sign in to comment.