[libchamplain] Bug 592096: champlain_map_source_desc_copy and _free are incomplete



commit 8a7e99efa96c8dd084c352051ec7f2ccb0760c34
Author: Pierre-Luc Beaudoin <pierre-luc pierlux com>
Date:   Tue Aug 25 19:07:33 2009 -0400

    Bug 592096: champlain_map_source_desc_copy and _free are incomplete

 champlain/champlain-map-source-desc.c |   44 +++++++++++++++++++++++++++++---
 1 files changed, 39 insertions(+), 5 deletions(-)
---
diff --git a/champlain/champlain-map-source-desc.c b/champlain/champlain-map-source-desc.c
index cfeaeca..58cc305 100644
--- a/champlain/champlain-map-source-desc.c
+++ b/champlain/champlain-map-source-desc.c
@@ -46,7 +46,8 @@ champlain_map_source_desc_get_type (void)
  * @desc: a #ChamplainMapSourceDesc
  *
  * Makes a copy of the map source desc structure.  The result must be
- * freed using champlain_map_source_desc_free().
+ * freed using #champlain_map_source_desc_free.  All string fields will
+ * be duplicated with #g_strdup.
  *
  * Return value: an allocated copy of @desc.
  *
@@ -55,10 +56,30 @@ champlain_map_source_desc_get_type (void)
 ChamplainMapSourceDesc *
 champlain_map_source_desc_copy (const ChamplainMapSourceDesc *desc)
 {
-  if (G_LIKELY (desc != NULL))
-    return g_slice_dup (ChamplainMapSourceDesc, desc);
+  ChamplainMapSourceDesc *dest = NULL;
+  if (G_UNLIKELY (desc == NULL))
+    return NULL;
+
+  dest = g_slice_dup (ChamplainMapSourceDesc, desc);
+  if (G_LIKELY (desc->id != NULL))
+    dest->id = g_strdup (desc->id);
+
+  if (G_LIKELY (desc->name != NULL))
+    dest->name = g_strdup (desc->name);
+
+  if (G_LIKELY (desc->license != NULL))
+    dest->license = g_strdup (desc->license);
+
+  if (G_LIKELY (desc->license_uri != NULL))
+    dest->license_uri = g_strdup (desc->license_uri);
 
-  return NULL;
+  if (G_LIKELY (desc->uri_format != NULL))
+    dest->uri_format = g_strdup (desc->uri_format);
+
+  // Can't make a copy of obscure pointer data
+  dest->data = desc->data;
+
+  return dest;
 }
 
 /**
@@ -66,7 +87,8 @@ champlain_map_source_desc_copy (const ChamplainMapSourceDesc *desc)
  * @desc: a #ChamplainMapSourceDesc
  *
  * Frees a desc structure created with #champlain_map_source_desc_new or
- * #champlain_map_source_desc_copy
+ * #champlain_map_source_desc_copy. All strings will be freed with #g_free.
+ * The data pointer will not be freed.
  *
  * Since: 0.4
  */
@@ -80,6 +102,18 @@ champlain_map_source_desc_free (ChamplainMapSourceDesc *desc)
   if (G_LIKELY (desc->id != NULL))
     g_free (desc->id);
 
+  if (G_LIKELY (desc->name != NULL))
+    g_free (desc->name);
+
+  if (G_LIKELY (desc->license != NULL))
+    g_free (desc->license);
+
+  if (G_LIKELY (desc->license_uri != NULL))
+    g_free (desc->license_uri);
+
+  if (G_LIKELY (desc->uri_format != NULL))
+    g_free (desc->uri_format);
+
   g_slice_free (ChamplainMapSourceDesc, desc);
 }
 



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