r19985 - gnucash/trunk/src/app-utils - Patch some memory leaks. scm_to_locale_string() returns a string which must be freed

Phil Longstaff plongstaff at rogers.com
Tue Dec 28 20:55:54 EST 2010


On Tue, 2010-12-28 at 20:49 -0500, Phil Longstaff wrote:
> Hey.  You top-posted.  :)
> 
> Anyhow,
> 
> from
> http://www.gnu.org/software/guile/manual/html_node/Conversion-to_002ffrom-C.html
> 
> — C Function: char * scm_to_locale_string (SCM str)
> — C Function: char * scm_to_locale_stringn (SCM str, size_t *lenp)
>         Returns a C string in the current locale encoding with the same
>         contents as str. The C string must be freed with free
>         eventually, maybe by using scm_dynwind_free, See Dynamic Wind. 
>         
>         For scm_to_locale_string, the returned string is null-terminated
>         and an error is signalled when str contains #\nul characters. 
>         
> You're right.  OK.

To follow up, I'll replace:

    s = g_strdup(scm_to_locale_string(xyz));

with:

    x = scm_to_locale_string(xyz);
    s = g_strdup(x);
    free(x);

so that any strings whose pointer is stored or returned from a function
comes from g_malloc() and will be freed by g_free(), rather than a mix
of malloc() and g_malloc().



More information about the gnucash-devel mailing list