diff --git a/src/app-utils/guile-util.c b/src/app-utils/guile-util.c index 37e58e416f..6c6e4d448d 100644 --- a/src/app-utils/guile-util.c +++ b/src/app-utils/guile-util.c @@ -168,10 +168,11 @@ gnc_guile_call1_to_string(SCM func, SCM arg) x = scm_to_locale_string(value); - /* scm_to_locale_string() returns a malloc'ed string. - Copy to a g_malloc'ed one. */ + /* scm_to_locale_string() returns a malloc'ed string in + guile-1.8 (but not in guile-1.6). Copy to a + g_malloc'ed one. */ s = g_strdup(x); - free(x); + gnc_free_scm_locale_string(x); return s; } else @@ -675,10 +676,11 @@ gnc_split_scm_get_memo(SCM split_scm) x = scm_to_locale_string(result); - /* scm_to_locale_string() returns a malloc'ed string. + /* scm_to_locale_string() returns a malloc'ed string in + guile-1.8 (but not in guile-1.6). Copy to a g_malloc'ed one. */ s = g_strdup(x); - free(x); + gnc_free_scm_locale_string(x); return s; } @@ -708,10 +710,11 @@ gnc_split_scm_get_action(SCM split_scm) x = scm_to_locale_string(result); - /* scm_to_locale_string() returns a malloc'ed string. + /* scm_to_locale_string() returns a malloc'ed string in + guile-1.8 (but not in guile-1.6). Copy to a g_malloc'ed one. */ s = g_strdup(x); - free(x); + gnc_free_scm_locale_string(x); return s; } @@ -1146,10 +1149,11 @@ gnc_get_debit_string(GNCAccountType account_type) x = scm_to_locale_string(result); - /* scm_to_locale_string() returns a malloc'ed string. + /* scm_to_locale_string() returns a malloc'ed string in + guile-1.8 (but not in guile-1.6). Copy to a g_malloc'ed one. */ s = g_strdup(x); - free(x); + gnc_free_scm_locale_string(x); return s; } @@ -1186,10 +1190,11 @@ gnc_get_credit_string(GNCAccountType account_type) x = scm_to_locale_string(result); - /* scm_to_locale_string() returns a malloc'ed string. + /* scm_to_locale_string() returns a malloc'ed string in + guile-1.8 (but not in guile-1.6). Copy to a g_malloc'ed one. */ s = g_strdup(x); - free(x); + gnc_free_scm_locale_string(x); return s; } diff --git a/src/gnome-utils/gnc-menu-extensions.c b/src/gnome-utils/gnc-menu-extensions.c index a7b586d906..95743f26bd 100644 --- a/src/gnome-utils/gnc-menu-extensions.c +++ b/src/gnome-utils/gnc-menu-extensions.c @@ -184,7 +184,7 @@ gnc_extension_path (SCM extension, char **fullpath) { strings[i] = g_strdup(gettext(s)); } - free(s); + gnc_free_scm_locale_string(s); } else { diff --git a/src/guile-mappings.h b/src/guile-mappings.h index 4a5c7bee66..7ae8859b31 100644 --- a/src/guile-mappings.h +++ b/src/guile-mappings.h @@ -30,11 +30,22 @@ # define scm_is_symbol SCM_SYMBOLP # define scm_is_true SCM_NFALSEP # define scm_is_vector SCM_VECTORP -# define scm_to_locale_string SCM_STRING_CHARS # define scm_c_string_length SCM_STRING_LENGTH #elif (SCM_MAJOR_VERSION == 1) && (SCM_MINOR_VERSION <= 8) # define scm_c_string_length scm_i_string_length #endif + +/* The result of SCM_STRING_CHARS must not be free'd, but the result + * of scm_to_locale_string must. That's bad. We define the macro + * gnc_free_scm_locale_string to wrap around free() for that + * reason. */ +#if (SCM_MAJOR_VERSION == 1) && (SCM_MINOR_VERSION <= 6) +# define scm_to_locale_string SCM_STRING_CHARS +# define gnc_free_scm_locale_string (void) +#else +# define gnc_free_scm_locale_string free +#endif + /* Convenience macros */ #define scm_is_equal(obj1,obj2) scm_is_true(scm_equal_p(obj1,obj2))