# HG changeset patch
# Node ID f1eb3edbfb68
# Parent  44c107f92a65
diff --git a/ChangeLog.API b/ChangeLog.API
--- a/ChangeLog.API
+++ b/ChangeLog.API
@@ -48,6 +48,7 @@
 		* purple_request_certificate
 		* purple_request_field_certificate_new
 		* purple_request_field_certificate_get_value
+		* purple_request_field_choice_add_full
 		* purple_request_field_get_tooltip
 		* purple_request_field_group_get_fields_list
 		* purple_request_field_set_tooltip
@@ -492,6 +493,8 @@
 		* purple_quotedp_decode. See the GMime library if needed.
 		* purple_restore_default_signal_handlers
 		* purple_request_certificate
+		* purple_request_field_choice_set_data_destructor. Use
+		  purple_request_field_choice_add_full instead
 		* purple_request_field_list_add
 		* PurpleSetPublicAliasFailureCallback
 		* PurpleSetPublicAliasSuccessCallback
diff --git a/libpurple/protocols/jabber/jabber.c b/libpurple/protocols/jabber/jabber.c
--- a/libpurple/protocols/jabber/jabber.c
+++ b/libpurple/protocols/jabber/jabber.c
@@ -3369,8 +3369,6 @@
 		PurpleRequestFieldGroup *group;
 		JabberMediaRequest *request;
 
-		purple_request_field_choice_set_data_destructor(field, g_free);
-
 		for(l = jb->resources; l; l = l->next)
 		{
 			JabberBuddyResource *ljbr = l->data;
@@ -3384,19 +3382,19 @@
 					(type & PURPLE_MEDIA_VIDEO)) {
 				if (caps & PURPLE_MEDIA_CAPS_AUDIO_VIDEO) {
 					jbr = ljbr;
-					purple_request_field_choice_add(field,
-						jbr->name, g_strdup(jbr->name));
+					purple_request_field_choice_add_full(field,
+					        jbr->name, g_strdup(jbr->name), g_free);
 				}
 			} else if (type & (PURPLE_MEDIA_AUDIO) &&
 					(caps & PURPLE_MEDIA_CAPS_AUDIO)) {
 				jbr = ljbr;
-				purple_request_field_choice_add(field,
-					jbr->name, g_strdup(jbr->name));
+				purple_request_field_choice_add_full(field,
+				        jbr->name, g_strdup(jbr->name), g_free);
 			}else if (type & (PURPLE_MEDIA_VIDEO) &&
 					(caps & PURPLE_MEDIA_CAPS_VIDEO)) {
 				jbr = ljbr;
-				purple_request_field_choice_add(field,
-					jbr->name, g_strdup(jbr->name));
+				purple_request_field_choice_add_full(field,
+				        jbr->name, g_strdup(jbr->name), g_free);
 			}
 		}
 
diff --git a/libpurple/protocols/jabber/si.c b/libpurple/protocols/jabber/si.c
--- a/libpurple/protocols/jabber/si.c
+++ b/libpurple/protocols/jabber/si.c
@@ -1594,11 +1594,9 @@
 			PurpleRequestField *field = purple_request_field_choice_new("resource", _("Resource"), 0);
 			PurpleRequestFieldGroup *group = purple_request_field_group_new(NULL);
 
-			purple_request_field_choice_set_data_destructor(field, g_free);
-
 			for(l = resources; l; l = l->next) {
 				jbr = l->data;
-				purple_request_field_choice_add(field, jbr->name, g_strdup(jbr->name));
+				purple_request_field_choice_add_full(field, jbr->name, g_strdup(jbr->name), g_free);
 			}
 
 			purple_request_field_group_add_field(group, field);
diff --git a/libpurple/protocols/jabber/xdata.c b/libpurple/protocols/jabber/xdata.c
--- a/libpurple/protocols/jabber/xdata.c
+++ b/libpurple/protocols/jabber/xdata.c
@@ -361,7 +361,6 @@
 		data->actiongroup = group = purple_request_field_group_new(_("Actions"));
 		purple_request_fields_add_group(fields, group);
 		actionfield = purple_request_field_choice_new("libpurple:jabber:xdata:actions", _("Select an action"), GINT_TO_POINTER(defaultaction));
-		purple_request_field_choice_set_data_destructor(actionfield, g_free);
 
 		for(i = 0, action = actions; action; action = g_list_next(action), i++) {
 			JabberXDataAction *a = action->data;
diff --git a/libpurple/request.h b/libpurple/request.h
--- a/libpurple/request.h
+++ b/libpurple/request.h
@@ -1432,6 +1432,21 @@
 	gpointer data);
 
 /**
+ * purple_request_field_choice_add_full:
+ * @field: The choice field.
+ * @label: The choice label.
+ * @data:  The choice value.
+ * @destroy: The value destroy function.
+ *
+ * Adds a choice to a multiple choice field with destructor for value.
+ *
+ * Since: 3.0.0
+ */
+void
+purple_request_field_choice_add_full(PurpleRequestField *field, const char *label,
+                                     gpointer data, GDestroyNotify destroy);
+
+/**
  * purple_request_field_choice_set_default_value:
  * @field:         The field.
  * @default_value: The default value.
@@ -1486,17 +1501,6 @@
 GList *
 purple_request_field_choice_get_elements(const PurpleRequestField *field);
 
-/**
- * purple_request_field_choice_set_data_destructor:
- * @field:   The field.
- * @destroy: The destroy function.
- *
- * Sets the destructor for field values.
- */
-void
-purple_request_field_choice_set_data_destructor(PurpleRequestField *field,
-	GDestroyNotify destroy);
-
 /**************************************************************************/
 /* List Field API                                                         */
 /**************************************************************************/
diff --git a/libpurple/request.c b/libpurple/request.c
--- a/libpurple/request.c
+++ b/libpurple/request.c
@@ -93,7 +93,6 @@
 			gpointer value;
 
 			GList *elements;
-			GDestroyNotify data_destroy;
 		} choice;
 
 		struct
@@ -944,14 +943,7 @@
 	}
 	else if (field->type == PURPLE_REQUEST_FIELD_CHOICE)
 	{
-		for (GList *it = field->u.choice.elements; it != NULL; it = g_list_next(it)) {
-			PurpleKeyValuePair *choice = it->data;
-
-			if (choice->value && field->u.choice.data_destroy)
-				field->u.choice.data_destroy(choice->value);
-			purple_key_value_pair_free(choice);
-		}
-		g_list_free(field->u.choice.elements);
+		g_list_free_full(field->u.choice.elements, (GDestroyNotify)purple_key_value_pair_free);
 	}
 	else if (field->type == PURPLE_REQUEST_FIELD_LIST)
 	{
@@ -1467,13 +1459,20 @@
 purple_request_field_choice_add(PurpleRequestField *field, const char *label,
 	gpointer value)
 {
+	purple_request_field_choice_add_full(field, label, value, NULL);
+}
+
+void
+purple_request_field_choice_add_full(PurpleRequestField *field, const char *label,
+                                     gpointer value, GDestroyNotify destroy)
+{
 	PurpleKeyValuePair *choice;
 
 	g_return_if_fail(field != NULL);
 	g_return_if_fail(label != NULL);
 	g_return_if_fail(field->type == PURPLE_REQUEST_FIELD_CHOICE);
 
-	choice = purple_key_value_pair_new(label, value);
+	choice = purple_key_value_pair_new_full(label, value, destroy);
 
 	field->u.choice.elements = g_list_append(field->u.choice.elements,
 		choice);
@@ -1527,16 +1526,6 @@
 	return field->u.choice.elements;
 }
 
-void
-purple_request_field_choice_set_data_destructor(PurpleRequestField *field,
-	GDestroyNotify destroy)
-{
-	g_return_if_fail(field != NULL);
-	g_return_if_fail(field->type == PURPLE_REQUEST_FIELD_CHOICE);
-
-	field->u.choice.data_destroy = destroy;
-}
-
 PurpleRequestField *
 purple_request_field_list_new(const char *id, const char *text)
 {
