changeset 13102:5828d42e8684

[gaim-migrate @ 15464] g_strdup() and free the label for a menu action. This way, if a plugin builds the label dynamically, we won't leak. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Thu, 02 Feb 2006 19:35:32 +0000
parents 094d4b49e1c9
children a6811e213977
files plugins/ChangeLog.API src/gtkutils.c src/util.c src/util.h
diffstat 4 files changed, 22 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/ChangeLog.API	Thu Feb 02 19:17:49 2006 +0000
+++ b/plugins/ChangeLog.API	Thu Feb 02 19:35:32 2006 +0000
@@ -244,6 +244,7 @@
 	* gaim_gtk_log_uninit()
 	* gaim_url_fetch_request()
 	* gaim_menu_action_new()
+	* gaim_menu_action_free()
 
 	Signals - Changed:  (See the Doxygen docs for details on all signals.)
 	* Signal propagation now stops after a handler returns a non-NULL value.
--- a/src/gtkutils.c	Thu Feb 02 19:17:49 2006 +0000
+++ b/src/gtkutils.c	Thu Feb 02 19:35:32 2006 +0000
@@ -1739,6 +1739,6 @@
 			g_list_free(act->children);
 			act->children = NULL;
 		}
-		g_free(act);
+		gaim_menu_action_free(act);
 	}
 }
--- a/src/util.c	Thu Feb 02 19:17:49 2006 +0000
+++ b/src/util.c	Thu Feb 02 19:35:32 2006 +0000
@@ -66,17 +66,26 @@
 static char home_dir[MAXPATHLEN];
 
 GaimMenuAction *
-gaim_menu_action_new(char *label, GaimCallback callback, gpointer data,
+gaim_menu_action_new(const char *label, GaimCallback callback, gpointer data,
                      GList *children)
 {
 	GaimMenuAction *act = g_new0(GaimMenuAction, 1);
-	act->label = label;
+	act->label = g_strdup(label);
 	act->callback = callback;
 	act->data = data;
 	act->children = children;
 	return act;
 }
 
+void
+gaim_menu_action_free(GaimMenuAction *act)
+{
+	g_return_if_fail(act != NULL);
+
+	g_free(act->label);
+	g_free(act);
+}
+
 /**************************************************************************
  * Base16 Functions
  **************************************************************************/
--- a/src/util.h	Thu Feb 02 19:17:49 2006 +0000
+++ b/src/util.h	Thu Feb 02 19:35:32 2006 +0000
@@ -60,6 +60,7 @@
 
 /**
  * Creates a new GaimMenuAction.
+ *
  * @param label    The text label to display for this action.
  * @param callback The function to be called when the action is used on
  *                 the selected item.
@@ -68,9 +69,16 @@
  *                 of the action.
  * @return The GaimMenuAction.
  */
-GaimMenuAction *gaim_menu_action_new(char *label, GaimCallback callback,
+GaimMenuAction *gaim_menu_action_new(const char *label, GaimCallback callback,
                                      gpointer data, GList *children);
 
+/**
+ * Frees a GaimMenuAction
+ *
+ * @param act The GaimMenuAction to free.
+ */
+void gaim_menu_action_free(GaimMenuAction *act);
+
 /**************************************************************************/
 /** @name Base16 Functions                                                */
 /**************************************************************************/