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:49:49 EST 2010
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.
On Tue, 2010-12-28 at 20:42 -0500, Derek Atkins wrote:
> Phil,
>
> Are you sure that scm_to_locale_string() is returning a g_alloc'ed string
> and not a malloc'ed string? You cannot mix-and-match malloc/free and
> g_alloc/g_free.
>
> -derek
>
> On Tue, December 28, 2010 8:36 pm, Phil Longstaff wrote:
> > Author: plongstaff
> > Date: 2010-12-28 20:36:26 -0500 (Tue, 28 Dec 2010)
> > New Revision: 19985
> > Trac: http://svn.gnucash.org/trac/changeset/19985
> >
> > Modified:
> > gnucash/trunk/src/app-utils/guile-util.c
> > Log:
> > Patch some memory leaks. scm_to_locale_string() returns a string which
> > must be freed
> >
> >
> > Modified: gnucash/trunk/src/app-utils/guile-util.c
> > ===================================================================
> > --- gnucash/trunk/src/app-utils/guile-util.c 2010-12-28 20:44:25 UTC (rev
> > 19984)
> > +++ gnucash/trunk/src/app-utils/guile-util.c 2010-12-29 01:36:26 UTC (rev
> > 19985)
> > @@ -162,7 +162,7 @@
> > value = scm_call_1(func, arg);
> >
> > if (scm_is_string(value))
> > - return g_strdup(scm_to_locale_string(value));
> > + return scm_to_locale_string(value);
> > else
> > {
> > PERR("bad value\n");
> > @@ -660,7 +660,7 @@
> > if (!scm_is_string(result))
> > return NULL;
> >
> > - return g_strdup(scm_to_locale_string(result));
> > + return scm_to_locale_string(result);
> > }
> >
> >
> > @@ -685,7 +685,7 @@
> > if (!scm_is_string(result))
> > return NULL;
> >
> > - return g_strdup(scm_to_locale_string(result));
> > + return scm_to_locale_string(result);
> > }
> >
> >
> > @@ -1115,10 +1115,7 @@
> > if (!scm_is_string(result))
> > return NULL;
> >
> > - string = scm_to_locale_string(result);
> > - if (string)
> > - return g_strdup(string);
> > - return NULL;
> > + return scm_to_locale_string(result);
> > }
> >
> >
> > @@ -1150,10 +1147,7 @@
> > if (!scm_is_string(result))
> > return NULL;
> >
> > - string = scm_to_locale_string(result);
> > - if (string)
> > - return g_strdup(string);
> > - return NULL;
> > + return scm_to_locale_string(result);
> > }
> >
> >
> >
> > _______________________________________________
> > gnucash-changes mailing list
> > gnucash-changes at gnucash.org
> > https://lists.gnucash.org/mailman/listinfo/gnucash-changes
> >
>
> _______________________________________________
> gnucash-devel mailing list
> gnucash-devel at gnucash.org
> https://lists.gnucash.org/mailman/listinfo/gnucash-devel
More information about the gnucash-devel
mailing list