Page 1 of 1

Segmentation fault loading PDF - OSX, threaded, magickwand

Posted: 2011-11-17T05:34:32-07:00
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

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

Posted: 2011-11-17T05:36:34-07:00
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.