r22685 - gnucash/trunk/src - Properly use scm_dynwind_* functions where they still make sense
Geert Janssens
gjanssens at code.gnucash.org
Sat Dec 22 13:20:40 EST 2012
Author: gjanssens
Date: 2012-12-22 13:20:39 -0500 (Sat, 22 Dec 2012)
New Revision: 22685
Trac: http://svn.gnucash.org/trac/changeset/22685
Modified:
gnucash/trunk/src/app-utils/gnc-ui-util.c
gnucash/trunk/src/engine/engine-helpers.c
Log:
Properly use scm_dynwind_* functions where they still make sense
Modified: gnucash/trunk/src/app-utils/gnc-ui-util.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-util.c 2012-12-22 18:20:29 UTC (rev 22684)
+++ gnucash/trunk/src/app-utils/gnc-ui-util.c 2012-12-22 18:20:39 UTC (rev 22685)
@@ -55,6 +55,7 @@
#include "gnc-locale-utils.h"
#include "gnc-component-manager.h"
#include "gnc-features.h"
+#include "gnc-guile-utils.h"
#define KEY_CURRENCY_CHOICE "currency_choice"
#define KEY_CURRENCY_OTHER "currency_other"
@@ -450,7 +451,13 @@
else
{
gchar *form = NULL;
- scm_dynwind_begin (0);
+
+ /* Note: using scm_to_locale_string directly here instead
+ of our wrapper gnc_scm_to_locale_string. 'form' should
+ be freed with 'free' instead of 'g_free'. This will
+ be taken care of automatically during scm_dynwind_end,
+ because we inform guile of this memory allocation via
+ scm_dynwind_free a little further. */
form = scm_to_locale_string (form_scm);
if (!form)
{
@@ -466,6 +473,11 @@
else
{
SCM desc_scm;
+
+ /* Create a dynwind context because we will be calling (scm) functions
+ that potentially exit non-locally */
+ scm_dynwind_begin (0);
+ scm_dynwind_free (form);
desc_scm = scm_call_3 (get_desc, category, code_scm,
tax_entity_type);
if (!scm_is_string (desc_scm))
@@ -482,7 +494,7 @@
else
{
gchar *desc = NULL;
- desc = scm_to_locale_string (desc_scm);
+ desc = gnc_scm_to_locale_string (desc_scm);
if (!desc)
{
if (tax_related)
@@ -519,11 +531,10 @@
}
g_free (copy_txt);
}
- scm_dynwind_free (desc);
+ g_free (desc);
}
+ scm_dynwind_end ();
}
- scm_dynwind_free (form);
- scm_dynwind_end ();
}
}
g_free (num_code);
Modified: gnucash/trunk/src/engine/engine-helpers.c
===================================================================
--- gnucash/trunk/src/engine/engine-helpers.c 2012-12-22 18:20:29 UTC (rev 22684)
+++ gnucash/trunk/src/engine/engine-helpers.c 2012-12-22 18:20:39 UTC (rev 22685)
@@ -981,23 +981,25 @@
if (!scm_is_string (key_scm))
continue;
+ key = scm_to_locale_string (key_scm); /* key should be freed with free !
+ This is automatically taken care
+ of by scm_dynwind_free below. */
scm_dynwind_begin (0);
- key = scm_to_locale_string (key_scm);
+ scm_dynwind_free (key); /* free key whenever the dynwind context ends */
if (!key)
{
- scm_dynwind_free (key);
scm_dynwind_end ();
continue;
}
- value = gnc_scm2KvpValue (val_scm);
+ value = gnc_scm2KvpValue (val_scm); /* can exit non-locally so justifies
+ the use of scm_dynwind context
+ protection */
if (!value)
{
- scm_dynwind_free (key);
scm_dynwind_end ();
continue;
}
kvp_frame_set_slot_nc (frame, key, value);
- scm_dynwind_free (key);
scm_dynwind_end ();
}
More information about the gnucash-changes
mailing list