Hi all,<br><br>I think I&#39;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()&#39;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&#39;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 &lt;cairo.h&gt;<br><br>int<br>main (int argc, char *argv[])<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cairo_surface_t *surface;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cairo_t *cr;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 240, 80);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cr = cairo_create (surface);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cairo_select_font_face (cr, &quot;serif&quot;, CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_BOLD);
<br>#if 0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cairo_set_font_size (cr, 32.0);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cairo_move_to (cr, 10.0, 50.0);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cairo_show_text (cr, &quot;Hello, world&quot;);<br>#endif<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cairo_destroy (cr);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cairo_surface_write_to_png (surface, &quot;hello.png&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cairo_surface_destroy (surface);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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:&nbsp;&nbsp; 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==&nbsp;&nbsp;&nbsp; at 0x4004405: malloc (vg_replace_malloc.c:149)
<br>==31669==&nbsp;&nbsp;&nbsp; by 0x805B7BC: _cairo_pattern_create_solid (cairo-pattern.c:309)<br>==31669==&nbsp;&nbsp;&nbsp; by 0x804EA54: _cairo_gstate_init (cairo-gstate.c:94)<br>==31669==&nbsp;&nbsp;&nbsp; by 0x804A073: cairo_create (cairo.c:210)<br>==31669==&nbsp;&nbsp;&nbsp; by 0x8049F86: main (in testImage)
<br>==31669== <br>==31669== LEAK SUMMARY:<br>==31669==&nbsp;&nbsp;&nbsp; definitely lost: 0 bytes in 0 blocks.<br>==31669==&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; possibly lost: 0 bytes in 0 blocks.<br>==31669==&nbsp;&nbsp;&nbsp; still reachable: 132 bytes in 1 blocks.<br>==31669==&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; suppressed: 0 bytes in 0 blocks.
<br>--31669--&nbsp; memcheck: sanity checks: 47 cheap, 2 expensive<br>--31669--&nbsp; memcheck: auxmaps: 0 auxmap entries (0k, 0M) in use<br>--31669--&nbsp; memcheck: auxmaps: 0 searches, 0 comparisons<br>--31669--&nbsp; memcheck: secondaries: 45 issued (2880k, 2M)
<br>--31669--&nbsp; memcheck: secondaries: 81 accessible and distinguished (5184k, 5M)<br>--31669--&nbsp;&nbsp;&nbsp;&nbsp; tt/tc: 7,958 tt lookups requiring 8,215 probes<br>--31669--&nbsp;&nbsp;&nbsp;&nbsp; tt/tc: 7,958 fast-cache updates, 3 flushes<br>--31669-- translate: new&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3,761 (81,413 -&gt; 1,340,177; ratio 164:10) [0 scs]
<br>--31669-- translate: dumped&nbsp;&nbsp;&nbsp;&nbsp; 0 (0 -&gt; ??)<br>--31669-- translate: discarded&nbsp; 9 (216 -&gt; ??)<br>--31669-- scheduler: 2,383,621 jumps (bb entries).<br>--31669-- scheduler: 47/4,707 major/minor sched events.<br>--31669--&nbsp;&nbsp;&nbsp; sanity: 48 cheap, 2 expensive checks.
<br>--31669--&nbsp;&nbsp;&nbsp; exectx: 30,011 lists, 62 contexts (avg 0 per list)<br>--31669--&nbsp;&nbsp;&nbsp; exectx: 93 searches, 31 full compares (333 per 1000)<br>--31669--&nbsp;&nbsp;&nbsp; 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>&lt;&nbsp;&nbsp;&nbsp;&nbsp; cairo_solid_pattern_t tmp_pattern;<br>&lt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memcpy(&amp;tmp_pattern, pattern, sizeof(pattern));<br>&lt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (pattern ) free(pattern);<br>
&lt;&nbsp;&nbsp;&nbsp;&nbsp; return &amp;tmp_pattern.base;<br>&lt;&nbsp;&nbsp;&nbsp;&nbsp; <br>---<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; return &amp;pattern-&gt;base;<br>[vuhung@ cairo-1.4.10]$<br><br>[vuhung@ Linux]$uname -a<br>Linux&nbsp; 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>