Thread

Posted on Sun Dec 25 13:13:05 2005 by milo
Perl Segmenattion fault or illegal Free
Hello, I'm using perl library GD-2.23 and system library gd-2.0.32. The following piece of perl code crashes the library. But only when part of a larger program. It works fine when run as stand-alone program... ===============================
<snip> my $graph; $graph = GD::Graph::lines->new(800, 600); $graph->set( x_label => 'Month', y_label => 'Amount', zero_axis => 1, title => 'Groups for each month (Amounts)', line_width => 2, x_labels_vertical => 1, legend_placement => 'BC' ); $graph->set_legend(@legend_keys); my $gd = $graph->plot(\@dataAbsolute); my $file = WebGUI::Attachment->new("graphAbsolute",$thisWobjectId); open(IMG, ">/tmp/graphAbsolute_$thisWobjectId.png"); binmode IMG; print IMG $gd->png(); #print IMG "Hoi"; IMG->close(); <snip>
=============================== I traced it down to the following stack: ===============================
#0 0xb7eb5182 in pthread_mutex_lock () from /lib/libpthread.so.0 #1 0xb7d78ced in free () from /lib/libc.so.6 #2 0xb6bdbfce in gdFree () from /usr/lib/libgd.so.2 #3 0x09bea30c in ?? () #4 0x098d63d8 in ?? () #5 0xb6de479c in ?? () from /usr/lib/perl5/vendor_perl/5.8.6/i686-linux/auto/GD/GD.so #6 0xb6dd57b7 in XS_GD__Image_png () from /usr/lib/perl5/vendor_perl/5.8.6/i686-linux/auto/GD/GD.s +o #7 0x0827b548 in ?? () #8 0xb791b424 in PL_utf8_tolower () from /usr/lib/libperl.so.1 #9 0x00001e04 in ?? () #10 0xb791199c in ?? () from /usr/lib/libperl.so.1 #11 0x098d9dc8 in ?? ()
=============================== And: ===============================
#0 0xb7d3f0b1 in kill () from /lib/libc.so.6 #1 0xb7eb71e1 in pthread_kill () from /lib/libpthread.so.0 #2 0xb7eb755b in raise () from /lib/libpthread.so.0 #3 0xb7d3ee44 in raise () from /lib/libc.so.6 #4 0xb7d4030d in abort () from /lib/libc.so.6 #5 0xb7d715bc in __fsetlocking () from /lib/libc.so.6 #6 0xb7d7b417 in mallopt () from /lib/libc.so.6 #7 0xb7d7a0df in mallopt () from /lib/libc.so.6 #8 0xb7d78ccf in free () from /lib/libc.so.6 #9 0xb6bdbfce in gdFree () from /usr/lib/libgd.so.2 #10 0x09b6f96c in ?? () #11 0x00001249 in ?? () #12 0xb6de479c in ?? () from /usr/lib/perl5/vendor_perl/5.8.6/i686-linux/auto/GD/GD.so #13 0xb6dd57b7 in XS_GD__Image_png () from /usr/lib/perl5/vendor_perl/5.8.6/i686-linux/auto/GD/GD.s +o #14 0x0827b548 in ?? () #15 0xb791b424 in PL_utf8_tolower () from /usr/lib/libperl.so.1 #16 0x00001249 in ?? () #17 0xb791199c in ?? () from /usr/lib/libperl.so.1 #18 0x0995c1bc in ?? ()
=============================== The error message is: ===============================
*** glibc detected *** free(): invalid pointer: 0x09be380c *** [Sat Dec 24 17:55:26 2005] [notice] child pid 16836 exit signal Aborted (6)
=============================== Or: ===============================
[Sat Dec 24 18:06:13 2005] [notice] child pid 16838 exit signal Segmentation fault (11)
=============================== I removed the gdFree(data) from the perl module (GD.xs) and now it runs fine... But probably with a memory leak... ===============================
<snip> #ifdef HAVE_PNG SV* gdpng(image, ...) GD::Image image PROTOTYPE: $;$ PREINIT: SV* errormsg; CODE: { void* data; int size; int level; if (items > 1) { level = (int)SvIV(ST(1)); data = (void *) gdImagePngPtrEx(image,&size,level); } else { data = (void *) gdImagePngPtr(image,&size); } RETVAL = newSVpv((char*) data,size); <br>gdFree(data); // <==== remove this and everything does run fine...</b> } OUTPUT: RETVAL #endif <snip>
=============================== Any suggestions? I can't find the bug but I do think it has to do with freeing memory that is not allocated. Does gdImagePngPtr() realy always allocate memory? MAG, Milo
Direct Responses: 1966 | Write a response
Posted on Sun Mar 19 18:04:25 2006 by matiu in response to 1512
Re: Perl Segmenattion fault or illegal Free
I have the same problem, using apache 2.0.55-r3(threads) + mod_perl 2.0.2 + GD + gd.2.0.33 on a amd64. I tried to compile everything again, reintall apache, gd, mod_perl, but the problem persist. The problem is not related with the graphic format: I get it for jpg, png and gif. Did you find any solution?
Write a response