[cairo] return type of cairo_status_to_string ()

Krzysztof Kosiński tweenk.pl at gmail.com
Wed Aug 18 08:32:36 PDT 2010


2010/8/18 Daniel Goldman <dagoldman at yahoo.com>:
> And Joonas' is right that cairo_status_to_string () could allocate memory. But I
> don't see how using "const char *" return type would obviate the need for the
> caller to free the memory. If the called function allocates memory, doesn't it
> need to be freed, no matter what the return type?

If you define the result as const char *, you will not be able to call
free() on it, because it will not compile. So defining the result type
as const char * indicates that the memory should not be freed by the
caller. If the return type was char *, you could accidentally call
free() on it, and the mistake would only manifest at runtime (crash).

Regards, Krzysztof


More information about the cairo mailing list