[yelp] Fixing memory management with params



commit 8f5b8a651ee49de8ff49e395c17f1b2853819d58
Author: Shaun McCance <shaunm gnome org>
Date:   Thu Jun 18 21:19:08 2009 -0500

    Fixing memory management with params
    
    I did this crazy thing long ago where every other string in the array way
    const, and you had to use a custom free function.  And somewhere along the
    way, the custom free function got lost, and it rotted into something that
    leaked half its memory and freed the other half twice.  So we're just going
    to go ahead and strdup and stop with the premature optimization.

 src/yelp-db-print.c |    1 +
 src/yelp-docbook.c  |    3 ++-
 src/yelp-info.c     |    1 +
 src/yelp-mallard.c  |    1 +
 src/yelp-man.c      |    1 +
 src/yelp-settings.c |    4 ++--
 src/yelp-toc.c      |    5 +++--
 7 files changed, 11 insertions(+), 5 deletions(-)
---
diff --git a/src/yelp-db-print.c b/src/yelp-db-print.c
index 61d7d1c..b85eea6 100644
--- a/src/yelp-db-print.c
+++ b/src/yelp-db-print.c
@@ -495,6 +495,7 @@ dbprint_process (YelpDbprint *dbprint)
     yelp_transform_start (priv->transform,
 			  priv->xmldoc,
 			  params);
+    g_strfreev (params);
     g_mutex_unlock (priv->mutex);
 
  done:
diff --git a/src/yelp-docbook.c b/src/yelp-docbook.c
index c7190e6..b2f45d7 100644
--- a/src/yelp-docbook.c
+++ b/src/yelp-docbook.c
@@ -496,7 +496,7 @@ docbook_process (YelpDocbook *docbook)
 	params_max += 20;
 	params = g_renew (gchar *, params, params_max);
     }
-    params[params_i++] = "db.chunk.max_depth";
+    params[params_i++] = g_strdup ("db.chunk.max_depth");
     params[params_i++] = g_strdup_printf ("%i", docbook->priv->max_depth);
 
     params[params_i] = NULL;
@@ -504,6 +504,7 @@ docbook_process (YelpDocbook *docbook)
     yelp_transform_start (priv->transform,
 			  priv->xmldoc,
 			  params);
+    g_strfreev (params);
     g_mutex_unlock (priv->mutex);
 
  done:
diff --git a/src/yelp-info.c b/src/yelp-info.c
index dd8343c..17a95c6 100644
--- a/src/yelp-info.c
+++ b/src/yelp-info.c
@@ -419,6 +419,7 @@ info_process (YelpInfo *info)
     yelp_transform_start (priv->transform,
 			  priv->xmldoc,
 			  params);
+    g_strfreev (params);
     g_mutex_unlock (priv->mutex);
 
  done:
diff --git a/src/yelp-mallard.c b/src/yelp-mallard.c
index 65304a6..f372b88 100644
--- a/src/yelp-mallard.c
+++ b/src/yelp-mallard.c
@@ -546,6 +546,7 @@ mallard_page_data_run (MallardPageData *page_data)
     yelp_transform_start (page_data->transform,
 			  page_data->xmldoc,
 			  params);
+    g_strfreev (params);
 }
 
 static void
diff --git a/src/yelp-man.c b/src/yelp-man.c
index 542b4eb..1e6fc56 100644
--- a/src/yelp-man.c
+++ b/src/yelp-man.c
@@ -481,6 +481,7 @@ man_process (YelpMan *man)
     yelp_transform_start (priv->transform,
 			  priv->xmldoc,
 			  params);
+    g_strfreev (params);
     g_mutex_unlock (priv->mutex);
 
  done:
diff --git a/src/yelp-settings.c b/src/yelp-settings.c
index 1213758..3aac246 100644
--- a/src/yelp-settings.c
+++ b/src/yelp-settings.c
@@ -842,13 +842,13 @@ yelp_settings_params (gchar ***params,
     }
 
     for (colors_i = 0; colors_i < YELP_NUM_COLORS; colors_i++) {
-	(*params)[(*params_i)++] = (gchar *) color_params[colors_i];
+	(*params)[(*params_i)++] = g_strdup ((gchar *) color_params[colors_i]);
 	(*params)[(*params_i)++] = g_strdup_printf ("\"%s\"",
 						yelp_settings_get_color (colors_i));
     }
 
     for (icons_i = 0; icons_i < YELP_NUM_ICONS; icons_i++) {
-	(*params)[(*params_i)++] = (gchar *) icon_params[icons_i];
+	(*params)[(*params_i)++] = g_strdup ((gchar *) icon_params[icons_i]);
 
 	icon_info = yelp_settings_get_icon (icons_i);
 	if (icon_info) {
diff --git a/src/yelp-toc.c b/src/yelp-toc.c
index b59a315..201cabb 100644
--- a/src/yelp-toc.c
+++ b/src/yelp-toc.c
@@ -504,10 +504,10 @@ toc_process (YelpToc *toc)
 
     info = gtk_icon_theme_lookup_icon (theme, "yelp-icon-big", 192, 0);
     if (info) {
-	params[params_i++] = "help_icon";
+	params[params_i++] = g_strdup ("help_icon");
 	params[params_i++] = g_strdup_printf ("\"%s\"",
 				      gtk_icon_info_get_filename (info));
-	params[params_i++] = "help_icon_size";
+	params[params_i++] = g_strdup ("help_icon_size");
 	params[params_i++] = g_strdup_printf ("%i",
 					      gtk_icon_info_get_base_size (info));
 	gtk_icon_info_free (info);
@@ -529,6 +529,7 @@ toc_process (YelpToc *toc)
     yelp_transform_start (priv->transform,
 			  priv->xmldoc,
 			  params);
+    g_strfreev (params);
     g_mutex_unlock (priv->mutex);
 
  done:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]