Add purple_key_value_pair_new_full with free function for value in PurpleKeyValuePair
--- a/libpurple/media/codec.c Wed Nov 27 00:34:58 2019 +0300
+++ b/libpurple/media/codec.c Sun Dec 01 15:36:50 2019 +0300
@@ -68,7 +68,7 @@
purple_media_codec_get_instance_private(
PURPLE_MEDIA_CODEC(info));
g_free(priv->encoding_name);
- g_list_free_full(priv->optional_params, (GDestroyNotify)purple_key_value_pair_free_full);
+ g_list_free_full(priv->optional_params, (GDestroyNotify)purple_key_value_pair_free); G_OBJECT_CLASS(purple_media_codec_parent_class)->finalize(info);
@@ -267,7 +267,7 @@
priv = purple_media_codec_get_instance_private(codec);
- new_param = purple_key_value_pair_new(name, g_strdup(value));
+ new_param = purple_key_value_pair_new_full(name, g_strdup(value), g_free); priv->optional_params = g_list_append(
priv->optional_params, new_param);
@@ -286,7 +286,7 @@
g_list_remove(priv->optional_params, param);
- purple_key_value_pair_free_full(param);
+ purple_key_value_pair_free(param); g_object_notify_by_pspec(G_OBJECT(codec), properties[PROP_OPTIONAL_PARAMS]);
--- a/libpurple/protocols/bonjour/mdns_common.c Wed Nov 27 00:34:58 2019 +0300
+++ b/libpurple/protocols/bonjour/mdns_common.c Sun Dec 01 15:36:50 2019 +0300
@@ -74,7 +74,7 @@
_add_txt_record(GSList *list, const gchar *key, const gchar *value)
const char *max_value = get_max_txt_record_value(key, value);
- PurpleKeyValuePair *kvp = purple_key_value_pair_new(key, g_strdup(max_value));
+ PurpleKeyValuePair *kvp = purple_key_value_pair_new_full(key, g_strdup(max_value), g_free); return g_slist_prepend(list, kvp);
@@ -142,7 +142,7 @@
txt_records = generate_presence_txt_records(data);
ret = _mdns_publish(data, type, txt_records);
- g_slist_free_full(txt_records, (GDestroyNotify)purple_key_value_pair_free_full);
+ g_slist_free_full(txt_records, (GDestroyNotify)purple_key_value_pair_free); --- a/libpurple/protocols/gg/gg.c Wed Nov 27 00:34:58 2019 +0300
+++ b/libpurple/protocols/gg/gg.c Sun Dec 01 15:36:50 2019 +0300
@@ -1040,7 +1040,7 @@
ggp_server_option = option;
#define ADD_VALUE(list, desc, v) { \
- PurpleKeyValuePair *kvp = purple_key_value_pair_new((desc), g_strdup((v))); \
+ PurpleKeyValuePair *kvp = purple_key_value_pair_new_full((desc), g_strdup((v)), g_free); \ list = g_list_append(list, kvp); \
--- a/libpurple/protocols/jabber/gtalk.c Wed Nov 27 00:34:58 2019 +0300
+++ b/libpurple/protocols/jabber/gtalk.c Sun Dec 01 15:36:50 2019 +0300
@@ -55,7 +55,7 @@
protocol->user_splits = g_list_append(protocol->user_splits, split);
#define ADD_VALUE(list, desc, v) { \
- PurpleKeyValuePair *kvp = purple_key_value_pair_new((desc), g_strdup((v))); \
+ PurpleKeyValuePair *kvp = purple_key_value_pair_new_full((desc), g_strdup((v)), g_free); \ list = g_list_prepend(list, kvp); \
--- a/libpurple/protocols/jabber/xmpp.c Wed Nov 27 00:34:58 2019 +0300
+++ b/libpurple/protocols/jabber/xmpp.c Sun Dec 01 15:36:50 2019 +0300
@@ -46,7 +46,7 @@
protocol->user_splits = g_list_append(protocol->user_splits, split);
#define ADD_VALUE(list, desc, v) { \
- PurpleKeyValuePair *kvp = purple_key_value_pair_new((desc), g_strdup((v))); \
+ PurpleKeyValuePair *kvp = purple_key_value_pair_new_full((desc), g_strdup((v)), g_free); \ list = g_list_prepend(list, kvp); \
--- a/libpurple/protocols/silc/silc.c Wed Nov 27 00:34:58 2019 +0300
+++ b/libpurple/protocols/silc/silc.c Sun Dec 01 15:36:50 2019 +0300
@@ -2171,7 +2171,7 @@
protocol->account_options = g_list_append(protocol->account_options, option);
for (i = 0; silc_default_ciphers[i].name; i++) {
- kvp = purple_key_value_pair_new(silc_default_ciphers[i].name, g_strdup(silc_default_ciphers[i].name));
+ kvp = purple_key_value_pair_new_full(silc_default_ciphers[i].name, g_strdup(silc_default_ciphers[i].name), g_free); list = g_list_append(list, kvp);
option = purple_account_option_list_new(_("Cipher"), "cipher", list);
@@ -2179,7 +2179,7 @@
for (i = 0; silc_default_hmacs[i].name; i++) {
- kvp = purple_key_value_pair_new(silc_default_hmacs[i].name, g_strdup(silc_default_hmacs[i].name));
+ kvp = purple_key_value_pair_new_full(silc_default_hmacs[i].name, g_strdup(silc_default_hmacs[i].name), g_free); list = g_list_append(list, kvp);
option = purple_account_option_list_new(_("HMAC"), "hmac", list);
--- a/libpurple/purpleaccountoption.c Wed Nov 27 00:34:58 2019 +0300
+++ b/libpurple/purpleaccountoption.c Sun Dec 01 15:36:50 2019 +0300
@@ -185,7 +185,7 @@
else if (option->type == PURPLE_PREF_STRING_LIST)
g_list_free_full(option->default_value.list,
- (GDestroyNotify)purple_key_value_pair_free_full);
+ (GDestroyNotify)purple_key_value_pair_free); @@ -247,7 +247,7 @@
g_return_if_fail(option->type == PURPLE_PREF_STRING_LIST);
g_list_free_full(option->default_value.list,
- (GDestroyNotify)purple_key_value_pair_free_full);
+ (GDestroyNotify)purple_key_value_pair_free); option->default_value.list = values;
@@ -263,7 +263,7 @@
g_return_if_fail(value != NULL);
g_return_if_fail(option->type == PURPLE_PREF_STRING_LIST);
- kvp = purple_key_value_pair_new(key, g_strdup(value));
+ kvp = purple_key_value_pair_new_full(key, g_strdup(value), g_free); option->default_value.list = g_list_append(option->default_value.list,
--- a/libpurple/util.c Wed Nov 27 00:34:58 2019 +0300
+++ b/libpurple/util.c Sun Dec 01 15:36:50 2019 +0300
@@ -3790,6 +3790,17 @@
kvp = g_new0(PurpleKeyValuePair, 1);
kvp->key = g_strdup(key);
+ kvp->value_destroy_func = NULL; +purple_key_value_pair_new_full(const char *key, gpointer value, GDestroyNotify value_destroy_func) + PurpleKeyValuePair *kvp = purple_key_value_pair_new(key, value); + kvp->value_destroy_func = value_destroy_func; @@ -3800,18 +3811,14 @@
g_return_if_fail(kvp != NULL);
+ if (kvp->value_destroy_func) { + kvp->value_destroy_func(kvp->value);
-purple_key_value_pair_free_full(PurpleKeyValuePair *kvp)
- g_return_if_fail(kvp != NULL);
- purple_key_value_pair_free(kvp);
--- a/libpurple/util.h Wed Nov 27 00:34:58 2019 +0300
+++ b/libpurple/util.h Sun Dec 01 15:36:50 2019 +0300
@@ -58,6 +58,7 @@
+ GDestroyNotify value_destroy_func; @@ -92,7 +93,8 @@
* @key: The key part of PurpleKeyValuePair
* @value: The value part of PurpleKeyValuePair
- * Creates a new PurpleKeyValuePair allocating memory for @key.
+ * Creates a new PurpleKeyValuePair allocating memory for @key, + * free value function is NULL. * Returns: The created PurpleKeyValuePair
@@ -101,25 +103,30 @@
PurpleKeyValuePair *purple_key_value_pair_new(const char *key, gpointer value);
+ * purple_key_value_pair_new_full: + * @key: The key part of PurpleKeyValuePair + * @value: The value part of PurpleKeyValuePair + * @value_destroy_func: a function to free the memory for the @value + * Creates a new PurpleKeyValuePair allocating memory for @key, + * set free value function to @value_destroy_func. + * Returns: The created PurpleKeyValuePair +PurpleKeyValuePair *purple_key_value_pair_new_full(const char *key, gpointer value, GDestroyNotify value_destroy_func); * purple_key_value_pair_free:
* @kvp: The PurpleKeyValuePair to free.
- * Frees @kvp->key and @kvp.
void purple_key_value_pair_free(PurpleKeyValuePair *kvp);
- * purple_key_value_pair_free_full:
- * @kvp: The PurpleKeyValuePair to free.
- * Does same as purple_key_value_pair_free and also frees @kvp->value.
-void purple_key_value_pair_free_full(PurpleKeyValuePair *kvp);
/**************************************************************************/
/**************************************************************************/