Hi all,<br><br>I think I've found a memory leak in cairo 1.4.10, file cairo-pattern.c, function _cairo_pattern_create_solid.<br>In that function, variable *pattern is malloc()'ed but has not free() yet.<br><br>I am not so surely this is a bug because I am quite new to C and cairo. Please excuse me If I am wrong.
<br><br>As you can see in the following details, I've detected this issue with valgrind. <br>If this bug is real, then cairo possiblely contains many similar problems in other files/functions.<br><br>I also include a diff of origin src/cairo-
pattern.c and the a ( possible ) FIXED cairo-pattern.c<br>Please see the following for details.<br><br><br>$cat test/test.cpp.ONLY.rairo <br>#include <cairo.h><br><br>int<br>main (int argc, char *argv[])<br>{<br> cairo_surface_t *surface;
<br> cairo_t *cr;<br><br> surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 240, 80);<br> cr = cairo_create (surface);<br><br> cairo_select_font_face (cr, "serif", CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_BOLD);
<br>#if 0<br> cairo_set_font_size (cr, 32.0);<br> cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);<br> cairo_move_to (cr, 10.0, 50.0);<br> cairo_show_text (cr, "Hello, world");<br>#endif<br>
cairo_destroy (cr);<br> cairo_surface_write_to_png (surface, "hello.png");<br> cairo_surface_destroy (surface);<br><br> return 0;<br>}<br><br>valgrind --leak-check=full -v --show-reachable=yes ./testImage
<br><br>[snip]<br>==31669== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 36 from 1)<br>--31669-- <br>--31669-- supp: 36 Ubuntu-stripped-ld.so<br>==31669== malloc/free: in use at exit: 132 bytes in 1 blocks.<br>==31669== malloc/free: 29 allocs, 28 frees, 362,305 bytes allocated.
<br>==31669== <br>==31669== searching for pointers to 1 not-freed blocks.<br>==31669== checked 370,744 bytes.<br>==31669== <br>==31669== 132 bytes in 1 blocks are still reachable in loss record 1 of 1<br>==31669== at 0x4004405: malloc (vg_replace_malloc.c:149)
<br>==31669== by 0x805B7BC: _cairo_pattern_create_solid (cairo-pattern.c:309)<br>==31669== by 0x804EA54: _cairo_gstate_init (cairo-gstate.c:94)<br>==31669== by 0x804A073: cairo_create (cairo.c:210)<br>==31669== by 0x8049F86: main (in testImage)
<br>==31669== <br>==31669== LEAK SUMMARY:<br>==31669== definitely lost: 0 bytes in 0 blocks.<br>==31669== possibly lost: 0 bytes in 0 blocks.<br>==31669== still reachable: 132 bytes in 1 blocks.<br>==31669== suppressed: 0 bytes in 0 blocks.
<br>--31669-- memcheck: sanity checks: 47 cheap, 2 expensive<br>--31669-- memcheck: auxmaps: 0 auxmap entries (0k, 0M) in use<br>--31669-- memcheck: auxmaps: 0 searches, 0 comparisons<br>--31669-- memcheck: secondaries: 45 issued (2880k, 2M)
<br>--31669-- memcheck: secondaries: 81 accessible and distinguished (5184k, 5M)<br>--31669-- tt/tc: 7,958 tt lookups requiring 8,215 probes<br>--31669-- tt/tc: 7,958 fast-cache updates, 3 flushes<br>--31669-- translate: new 3,761 (81,413 -> 1,340,177; ratio 164:10) [0 scs]
<br>--31669-- translate: dumped 0 (0 -> ??)<br>--31669-- translate: discarded 9 (216 -> ??)<br>--31669-- scheduler: 2,383,621 jumps (bb entries).<br>--31669-- scheduler: 47/4,707 major/minor sched events.<br>--31669-- sanity: 48 cheap, 2 expensive checks.
<br>--31669-- exectx: 30,011 lists, 62 contexts (avg 0 per list)<br>--31669-- exectx: 93 searches, 31 full compares (333 per 1000)<br>--31669-- exectx: 0 cmp2, 76 cmp4, 0 cmpAll<br><br>[vuhung@ cairo-1.4.10]$diff src/cairo-
pattern.c src/cairo-pattern.c.2007-10-12.orig <br>317,321c317<br>< cairo_solid_pattern_t tmp_pattern;<br>< memcpy(&tmp_pattern, pattern, sizeof(pattern));<br>< if (pattern ) free(pattern);<br>
< return &tmp_pattern.base;<br>< <br>---<br>> return &pattern->base;<br>[vuhung@ cairo-1.4.10]$<br><br>[vuhung@ Linux]$uname -a<br>Linux 2.6.9-42.ELsmp #1 SMP Wed Jul 12 23:27:17 EDT 2006 i686 GNU/Linux
<br>[vuhung@ Linux]$cat /etc/redhat-release <br>Red Hat Enterprise Linux ES release 4 (Nahant Update 4)<br>[vuhung@ Linux]$gcc --version<br>gcc (GCC) 3.4.6 20060404 (Red Hat 3.4.6-3)<br>[vuhung@ Linux]$rpm -qa | grep glibc
<br>glibc-headers-2.3.4-2.25<br>glibc-common-2.3.4-2.25<br>glibc-devel-2.3.4-2.25<br>glibc-2.3.4-2.25<br>glibc-kernheaders-2.4-9.1.98.EL<br>[vuhung@ ]$rpm -qa | grep valgr<br>valgrind-callgrind-0.10.1-2.EL4<br>valgrind-3.1.1-1.EL4
<br clear="all"><br>-- <br>Best Regards,<br>Nguyen Hung Vu<br><a href="mailto:vuhung16plus{remove}@gmail.dot.com">vuhung16plus{remove}@gmail.dot.com</a><br>An inquisitive look at Harajuku <br><a href="http://www.flickr.com/photos/vuhung/sets/72157600109218238/">
http://www.flickr.com/photos/vuhung/sets/72157600109218238/</a>