Segmentation fault loading PDF - OSX, threaded, magickwand

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
draxil
Posts: 7
Joined: 2011-11-17T05:18:40-07:00
Authentication code: 8675308

Segmentation fault loading PDF - OSX, threaded, magickwand

Post by draxil »

Hi,
I have some code which uses the glib threadpool API and the ImageMagick magick wand api. It runs on Linux and OSX and mostly deals with EPS and PDF formats.

On OSX when running in a thread and loading a PDF I get a segmentation fault. Using the same code under linux I do not. If I load other formats I also still get no fault. Also if I remove the threading element I also get no segfault.

I have boiled this down to the following simple test program which demonstrates the issue (correct /tmp/in.pdf to whatever):

Code: Select all

#include <glib.h>
#include <wand/magick-wand.h>

void process_request( gpointer data, gpointer mydata );
int main(void){
  g_thread_init(NULL);
  MagickWandGenesis();
  GMainLoop * gmlp = g_main_loop_new( NULL,  FALSE );
  GError * e = NULL;
  GThreadPool * pool =  g_thread_pool_new( process_request,
                                           NULL,
                                           6,
                                           FALSE,
                                           &e);

  g_thread_pool_push( pool, g_strdup("/tmp/in.pdf"), NULL );
  g_main_loop_run ( gmlp );
}
void process_request( gpointer data, gpointer mydata )
{
  gchar * in;
  gsize len;

  g_file_get_contents( (gchar*) data,
                       &in,
                       &len,
                       NULL );
  MagickWand * wand = NewMagickWand();

  g_warning("about to segfault...");
  MagickReadImageBlob( wand,
                       in,
                       len );
  g_warning("No I am fine!");
  gchar * fmt =  MagickGetImageFormat( wand );

  g_warning( "%s", fmt );
}
On the crashing machine I am using the ports version of image magick ( 6.7.3-1 ). Tried several PDFs so I don't think the contents are important, but I can supply one if needed.

Thanks!
Joe
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Segmentation fault loading PDF - OSX, threaded, magickwa

Post by magick »

Threads and OpenMP do not work well under MacOS X although its fine under Linux. Under MacOS X you must build ImageMagick without OpenMP support if you want to use threads. Grab the source and add --disable-openmp on the configure script command line.
Post Reply