summary refs log tree commit diff stats
path: root/src/fe-gtk/plugingui.c
diff options
context:
space:
mode:
authorTingPing <tingping@tingping.se>2014-12-28 06:37:25 -0500
committerTingPing <tingping@tingping.se>2014-12-28 06:44:44 -0500
commit83032b1aa3c3e5910c5cfd3e0ea1d25827f56475 (patch)
tree9be32a04d3070eac82177e11d182dad40a63baa7 /src/fe-gtk/plugingui.c
parentc4cb1b25ec06a5b0cb718c6f8e74630df9a9bc64 (diff)
Use glib for all allocations
- Removes need to check for malloc failure
- Removes need for NULL checks on free
- Adds checks for integer overflows
- Removes some extra memset calls
- Removes chance of mixing libc and glib malloc/free
Diffstat (limited to 'src/fe-gtk/plugingui.c')
-rw-r--r--src/fe-gtk/plugingui.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/fe-gtk/plugingui.c b/src/fe-gtk/plugingui.c
index 05d697f8..83e05727 100644
--- a/src/fe-gtk/plugingui.c
+++ b/src/fe-gtk/plugingui.c
@@ -142,14 +142,14 @@ plugingui_load_cb (session *sess, char *file)
 {
 	if (file)
 	{
-		char *buf = malloc (strlen (file) + 9);
+		char *buf;
 
 		if (strchr (file, ' '))
-			sprintf (buf, "LOAD \"%s\"", file);
+			buf = g_strdup_printf ("LOAD \"%s\"", file);
 		else
-			sprintf (buf, "LOAD %s", file);
+			buf = g_strdup_printf ("LOAD %s", file);
 		handle_command (sess, buf, FALSE);
-		free (buf);
+		g_free (buf);
 	}
 }
 
@@ -173,7 +173,7 @@ plugingui_loadbutton_cb (GtkWidget * wid, gpointer unused)
 static void
 plugingui_unload (GtkWidget * wid, gpointer unused)
 {
-	char *modname, *file, *buf;
+	char *modname, *file;
 	GtkTreeView *view;
 	GtkTreeIter iter;
 	
@@ -186,16 +186,17 @@ plugingui_unload (GtkWidget * wid, gpointer unused)
 	{
 		if (plugin_kill (modname, FALSE) == 2)
 			fe_message (_("That plugin is refusing to unload.\n"), FE_MSG_ERROR);
-	} else
+	}
+	else
 	{
+		char *buf;
 		/* let python.so or perl.so handle it */
-		buf = malloc (strlen (file) + 10);
 		if (strchr (file, ' '))
-			sprintf (buf, "UNLOAD \"%s\"", file);
+			buf = g_strdup_printf ("UNLOAD \"%s\"", file);
 		else
-			sprintf (buf, "UNLOAD %s", file);
+			buf = g_strdup_printf ("UNLOAD %s", file);
 		handle_command (current_sess, buf, FALSE);
-		free (buf);
+		g_free (buf);
 	}
 
 	g_free (modname);
@@ -209,14 +210,14 @@ plugingui_reloadbutton_cb (GtkWidget *wid, GtkTreeView *view)
 
 	if (file)
 	{
-		char *buf = malloc (strlen (file) + 9);
+		char *buf;
 
 		if (strchr (file, ' '))
-			sprintf (buf, "RELOAD \"%s\"", file);
+			buf = g_strdup_printf ("RELOAD \"%s\"", file);
 		else
-			sprintf (buf, "RELOAD %s", file);
+			buf = g_strdup_printf ("RELOAD %s", file);
 		handle_command (current_sess, buf, FALSE);
-		free (buf);
+		g_free (buf);
 		g_free (file);
 	}
 }