summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gabble/disco-identity.h1
-rw-r--r--src/caps-hash.c7
-rw-r--r--src/util.c38
3 files changed, 41 insertions, 5 deletions
diff --git a/gabble/disco-identity.h b/gabble/disco-identity.h
index 23f975e3f..992e24707 100644
--- a/gabble/disco-identity.h
+++ b/gabble/disco-identity.h
@@ -41,6 +41,7 @@ const gchar *gabble_disco_identity_get_name (GabbleDiscoIdentity *identity);
void gabble_disco_identity_free (GabbleDiscoIdentity *identity);
/* array of GabbleDiscoIdentity helper methods */
+GPtrArray *gabble_disco_identity_array_new (void);
GPtrArray *gabble_disco_identity_array_copy (const GPtrArray *source);
void gabble_disco_identity_array_free (GPtrArray *arr);
diff --git a/src/caps-hash.c b/src/caps-hash.c
index 55907e577..2f2258b5b 100644
--- a/src/caps-hash.c
+++ b/src/caps-hash.c
@@ -310,7 +310,7 @@ gchar *
caps_hash_compute_from_lm_node (LmMessageNode *node)
{
GPtrArray *features = g_ptr_array_new ();
- GPtrArray *identities = g_ptr_array_new ();
+ GPtrArray *identities = gabble_disco_identity_array_new ();
GPtrArray *dataforms = g_ptr_array_new ();
gchar *str;
NodeIter i;
@@ -397,7 +397,7 @@ caps_hash_compute_from_self_presence (GabbleConnection *self)
GabblePresence *presence = self->self_presence;
const GabbleCapabilitySet *cap_set;
GPtrArray *features = g_ptr_array_new ();
- GPtrArray *identities = g_ptr_array_new ();
+ GPtrArray *identities = gabble_disco_identity_array_new ();
GPtrArray *dataforms = g_ptr_array_new ();
gchar *str;
@@ -430,7 +430,8 @@ gabble_caps_hash_compute (const GabbleCapabilitySet *cap_set,
{
GPtrArray *features = g_ptr_array_new ();
GPtrArray *identities_copy = ((identities == NULL) ?
- g_ptr_array_new () : gabble_disco_identity_array_copy (identities));
+ gabble_disco_identity_array_new () :
+ gabble_disco_identity_array_copy (identities));
GPtrArray *dataforms = g_ptr_array_new ();
gchar *str;
diff --git a/src/util.c b/src/util.c
index e7d00e550..b92d5bb97 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1376,6 +1376,29 @@ gabble_disco_identity_free (GabbleDiscoIdentity *identity)
g_free (identity);
}
+/**
+ * Creates a new array of GabbleDiscoIdentity objects.
+ *
+ * \return A newly instantiated array.
+ * \sa gabble_disco_identity_array_free
+ */
+GPtrArray *
+gabble_disco_identity_array_new (void)
+{
+ return g_ptr_array_new_with_free_func (
+ (GDestroyNotify) gabble_disco_identity_free);
+}
+
+/**
+ * Copies an array of GabbleDiscoIdentity objects.
+ *
+ * The returned array contains new copies of the contents of the source array.
+ *
+ * \param source The source array to be copied.
+ * \return A newly instantiated array with new copies of the contents of the
+ * source array.
+ * \sa gabble_disco_identity_array_new
+ */
GPtrArray *
gabble_disco_identity_array_copy (const GPtrArray *source)
{
@@ -1386,6 +1409,7 @@ gabble_disco_identity_array_copy (const GPtrArray *source)
return NULL;
ret = g_ptr_array_sized_new (source->len);
+ g_ptr_array_set_free_func (ret, (GDestroyNotify) gabble_disco_identity_free);
for (i = 0; i < source->len; ++i)
{
g_ptr_array_add (ret,
@@ -1394,12 +1418,22 @@ gabble_disco_identity_array_copy (const GPtrArray *source)
return ret;
}
+/**
+ * Frees an array of GabbleDiscoIdentity objects created with
+ * gabble_disco_identity_array_new() or returned by
+ * gabble_disco_identity_array_copy().
+ *
+ * Note that if this method is called with an array created with
+ * g_ptr_array_new, the caller should also free the array contents.
+ *
+ * \param arr Array to be freed.
+ * \sa gabble_disco_identity_array_new, gabble_disco_identity_array_copy
+ */
void
gabble_disco_identity_array_free (GPtrArray *arr)
{
if (!arr)
return;
- g_ptr_array_foreach (arr,
- (GFunc) gabble_disco_identity_free, NULL);
+ g_ptr_array_free (arr, TRUE);
}