Page 1 of 1

Deadlock when memory allocation fails

Posted: 2009-11-24T05:12:28-07:00
by frankoid
ImageMagick version: 6.5.7-10
System: Linux (Debian Lenny/amd64)

I was trying to use ulimit -v to prevent ImageMagick from using a lot of virtual memory on a server and causing it to thrash. I have now discovered the MAGICK_AREA_LIMIT environment variable which seems like a better solution to my problem, but thought I'd report the bug I found anyway.

When I run identify as follows:

Code: Select all

ulimit -v 262144
/usr/local/bin/identify -format %w-@-%h-@-%r-@- -define pdf:use-cropbox=true /var/lib/tomcat5.5/webapps/asset-bank/files/0/MBA_final_doc.pdf
it hangs.

I attached to it with gdb to get a backtrace, and it looks like it is deadlocking when trying to get the MemoryAllocationFailed error message when the memory allocation in AcquirePixelCache fails:

Code: Select all

(gdb) bt
#0  0x00007fe85c061384 in __lll_lock_wait () from /lib/libpthread.so.0
#1  0x00007fe85c05cbf0 in _L_lock_102 () from /lib/libpthread.so.0
#2  0x00007fe85c05c4fe in pthread_mutex_lock () from /lib/libpthread.so.0
#3  0x00007fe85d7ce00e in LockSemaphoreInfo (semaphore_info=0x1d9d180) at magick/semaphore.c:294
#4  0x00007fe85d7887ea in LocaleComponentTerminus () at magick/locale.c:1077
#5  0x00007fe85d78e225 in MagickCoreTerminus () at magick/magick.c:1332
#6  0x00007fe85d760777 in DefaultFatalErrorHandler (magick_unused_severity=<value optimized out>,
    reason=0x1eadba0 "UnableToAcquireString `Cannot allocate memory' @ string.c/AcquireString/126", description=0x0) at magick/exception.c:308
#7  0x00007fe85d760de3 in CatchException (exception=0x7fff65cd1000) at magick/exception.c:220
#8  0x00007fe85d7e01c5 in AcquireString (
    source=0x7fe85d83df78 "<?xml version=\"1.0\"?><localemap>  <locale name=\"C\">    <Exception>     <Message name=\"\">     </Message>    </Exception>  </locale></localemap>") at magick/string.c:126
#9  0x00007fe85d788c97 in LoadLocaleList (
    xml=0x7fe85d83df78 "<?xml version=\"1.0\"?><localemap>  <locale name=\"C\">    <Exception>     <Message name=\"\">     </Message>    </Exception>  </locale></localemap>", filename=0x7fe85d82a237 "built-in", locale=0x1f5f3f0 "en_GB.UTF-8", depth=0, exception=0x1f5f240) at magick/locale.c:771
#10 0x00007fe85d7897af in GetLocaleInfo_ (tag=0x7fff65cd5180 "Exception/Resource/Limit/FatalError/MemoryAllocationFailed/", exception=0x1f5f240)
    at magick/locale.c:1026
#11 0x00007fe85d7898cc in GetLocaleMessage (tag=0x7fff65cd61a0 "Exception/Resource/Limit/FatalError/MemoryAllocationFailed") at magick/locale.c:403
#12 0x00007fe85d7607e1 in GetLocaleExceptionMessage (severity=<value optimized out>, tag=0x7fe85d8207a0 "MemoryAllocationFailed") at magick/exception.c:572
#13 0x00007fe85d7610c1 in ThrowMagickExceptionList (exception=0x7fff65cda320, module=0x7fe85d822bda "magick/cache.c",
    function=0x7fe85d823e40 "AcquirePixelCache", line=184, severity=FatalErrorException, tag=0x80 <Address 0x80 out of bounds>,
    format=0x7fe85d84bcf4 "`%s'", operands=0x7fff65cda230) at magick/exception.c:957
#14 0x00007fe85d7612ca in ThrowMagickException (exception=0x1d9d180, module=0x80 <Address 0x80 out of bounds>,
    function=0x7fe85c064990 "W{��\200|��M{���|��){��){��){��){��){��){��){��){��){��){��){��){��P}��P}��P}��P}��){��){��){��){��){��){��){��){��){��){��){��){���}���}���}���}��){��){��){��){��){��){��){��){��){��){��){��){���}���}��"..., line=18446744073709551615, severity=1571565728,
    tag=0xffffffff54535254 <Address 0xffffffff54535254 out of bounds>, format=0x7fe85d84bcf4 "`%s'") at magick/exception.c:987
#15 0x00007fe85d6dd2cb in AcquirePixelCache (number_threads=0) at magick/cache.c:196
#16 0x00007fe85d77ff9f in AcquireImage (image_info=0x1dcc3c0) at magick/image.c:182
#17 0x00007fe85d780b2d in AcquireNextImage (image_info=0x1dcc3c0, image=0x1f64e90) at magick/image.c:416
#18 0x00007fe85a45b757 in ?? ()
#19 0x0000000000000000 in ?? ()
(gdb) 

Re: Deadlock when memory allocation fails

Posted: 2009-11-24T07:30:28-07:00
by magick
Thanks for the problem report. We cannot reproduce the problem but understand its source. We'll have a patch in the next point release of ImageMagick.