[Telepathy-commits] [telepathy-gabble/master] Free temporary structures after hashing caps

Alban Crequy alban.crequy at collabora.co.uk
Tue Aug 19 10:52:33 PDT 2008


20080509162450-a41c0-75f8061bb2dc0af8a693122861c24b0c330ba84f.gz
---
 src/presence.c |   51 ++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/src/presence.c b/src/presence.c
index d4940be..fb7c6bd 100644
--- a/src/presence.c
+++ b/src/presence.c
@@ -571,6 +571,43 @@ gabble_presence_compute_xep0115_hash (
   return encoded;
 }
 
+static void
+_free_field (gpointer data, gpointer user_data)
+{
+  struct _dataform_field *field = data;
+
+  g_free (field->fieldname);
+  g_ptr_array_foreach (field->values, (GFunc) g_free, NULL);
+
+  g_slice_free1 (sizeof (struct _dataform_field), field);
+}
+
+static void
+_free_form (gpointer data, gpointer user_data)
+{
+  struct _dataform *form = data;
+
+  g_free (form->form_type);
+
+  g_ptr_array_foreach (form->fields, (GFunc) _free_field, NULL);
+
+  g_slice_free1 (sizeof (struct _dataform), form);
+}
+
+static void
+gabble_presence_free_xep0115_hash (
+    GPtrArray *features,
+    GPtrArray *identities,
+    GPtrArray *dataforms)
+{
+  g_ptr_array_foreach (features, (GFunc) g_free, NULL);
+  g_ptr_array_foreach (identities, (GFunc) g_free, NULL);
+  g_ptr_array_foreach (dataforms, (GFunc) _free_form, NULL);
+
+  g_ptr_array_free (features, TRUE);
+  g_ptr_array_free (identities, TRUE);
+  g_ptr_array_free (dataforms, TRUE);
+}
 
 /**
  *
@@ -690,10 +727,7 @@ gabble_presence_compute_xep0115_hash_from_lm_node (LmMessageNode *node)
 
   str = gabble_presence_compute_xep0115_hash (features, identities, dataforms);
 
-  g_ptr_array_free (features, TRUE);
-  g_ptr_array_free (identities, TRUE);
-  g_ptr_array_free (dataforms, TRUE);
-  /* TODO: also free content of dataforms */
+  gabble_presence_free_xep0115_hash (features, identities, dataforms);
 
   return str;
 }
@@ -714,19 +748,18 @@ gabble_presence_compute_xep0115_hash_from_self_presence (GabbleConnection *self)
   for (i = features_list; NULL != i; i = i->next)
     {
       const Feature *feat = (const Feature *) i->data;
-      g_ptr_array_add (features, (gpointer) feat->ns);
+      g_ptr_array_add (features, (gpointer) g_strdup (feat->ns));
     }
 
   /* XEP-0030 requires at least 1 identity. We don't need more. */
-  g_ptr_array_add (features, (gpointer) "client/pc//" PACKAGE_STRING);
+  g_ptr_array_add (identities,
+      (gpointer) g_strdup ("client/pc//" PACKAGE_STRING));
 
   /* Gabble does not use dataforms, let 'dataforms' be empty */
 
   str = gabble_presence_compute_xep0115_hash (features, identities, dataforms);
 
-  g_ptr_array_free (features, TRUE);
-  g_ptr_array_free (identities, TRUE);
-  g_ptr_array_free (dataforms, TRUE);
+  gabble_presence_free_xep0115_hash (features, identities, dataforms);
   g_slist_free (features_list);
 
   return str;
-- 
1.5.6.3




More information about the Telepathy-commits mailing list