[cairo] How to free the memory allocated by cairo_image_surface_create_for_png?

Charles Wang charles.wang at akomedia.com
Tue Apr 5 00:02:36 PDT 2005


Hi Carl:

Thanks for you quickly reply, got your idea. :)

I think you let me to do the following things:
d = malloc(...);
sr = cairo_image_surface_create_for_data(d, CAIRO_FORMAT_XXX, w, h,
stride);
cairo_surface_set_user_data(sr, "IMG", d, free);

It should be complex than just call
'caior_image_surface_assume_ownershipt_of_data' and might encounter key
conflict problem, The prototype of user data destroy callback must also
compatible with 'free' in libc, otherwise we have to define a callback
for this common simple position.

So if the '_cairo_image_surface_assume_ownership_of_data' is a public
function, we will do simple/safe/straightforward thing to avoid memory
leak.

How about it? Thanks. :)

Charles  April 5, 2005.

在 2005-04-04一的 12:48 -0400,Carl Worth写道:
> On Mon, 04 Apr 2005 14:12:29 +0800, Charles Wang wrote:
> > Is there any method to avoid this memory leak?
> 
> Thanks for the bug report. I've just committed a fix.
> 
> The fix I used takes advantage of a private function. But the same
> issue shows up in code outside of cairo. In that case,
> cairo_surface_set_user_data can be used to solve similar problems.
> 
> -Carl




More information about the cairo mailing list