Commit 0e200d76 authored by Jiri (George) Lebl's avatar Jiri (George) Lebl Committed by George Lebl

Make sure the AppletInfo is freed, fix a possible race with applet

Wed Jan 16 01:01:38 2002  George Lebl <jirka@5z.com>

	* applet.[ch], panel-applet-frame.c: Make sure the AppletInfo is
	  freed, fix a possible race with applet destruction.  There are
	  some somewhat evil things still around here.  Fear.

	* panel-util.[ch], applet.c, gnome-run.c, menu-fentry.c, menu.c,
	  panel.c: make deep_free list functions and use them
parent 141697f3
Wed Jan 16 01:01:38 2002 George Lebl <jirka@5z.com>
* applet.[ch], panel-applet-frame.c: Make sure the AppletInfo is
freed, fix a possible race with applet destruction. There are
some somewhat evil things still around here. Fear.
* panel-util.[ch], applet.c, gnome-run.c, menu-fentry.c, menu.c,
panel.c: make deep_free list functions and use them
Tue Jan 15 15:05:46 2002 George Lebl <jirka@5z.com>
* button-widget.[ch], panel-types.h, drawer.c, menu.c, launcher.c,
......
......@@ -117,8 +117,7 @@ panel_applet_clean_gconf (AppletInfo *info)
}
g_free (temp_key);
g_slist_foreach (id_list, (GFunc) g_free, NULL);
g_slist_free (id_list);
panel_g_slist_deep_free (id_list);
}
/*destroy widgets and call the above cleanup function*/
......@@ -127,24 +126,28 @@ panel_applet_clean (AppletInfo *info)
{
g_return_if_fail (info != NULL);
if (info->remove_idle != 0) {
g_source_remove (info->remove_idle);
info->remove_idle = 0;
}
panel_applet_clean_gconf (info);
applets = g_slist_remove (applets, info);
if (info->widget != NULL) {
GtkWidget *widget = info->widget;
if(info->type == APPLET_STATUS) {
status_applet_put_offscreen (info->data);
}
/* destroy will remove it from the panel */
gtk_widget_destroy (info->widget);
info->widget = NULL;
gtk_widget_destroy (widget);
}
info->data = NULL;
/*
* FIXME: where are we supposed to free the structure?
*/
g_free (info);
}
static gboolean
......@@ -152,6 +155,8 @@ applet_idle_remove (gpointer data)
{
AppletInfo *info = data;
info->remove_idle = 0;
panel_applet_save_position (info, info->gconf_key);
if (info->type == APPLET_SWALLOW) {
......@@ -169,7 +174,8 @@ static void
applet_remove_callback (GtkWidget *widget,
AppletInfo *info)
{
g_idle_add (applet_idle_remove, info);
if (info->remove_idle == 0)
info->remove_idle = g_idle_add (applet_idle_remove, info);
}
static void
......@@ -728,10 +734,12 @@ applet_button_press (GtkWidget *widget,
static void
applet_destroy (GtkWidget *w, AppletInfo *info)
{
GtkWidget *old_widget;
GList *li;
g_return_if_fail (info != NULL);
old_widget = info->widget;
info->widget = NULL;
if (info->type == APPLET_DRAWER) {
......@@ -786,6 +794,11 @@ applet_destroy (GtkWidget *w, AppletInfo *info)
}
g_list_free (info->user_menu);
info->user_menu = NULL;
/* If this was not called from the panel_applet_clean
* itself. That is if the widget entry was still set */
if (old_widget != NULL)
panel_applet_clean (info);
}
static char *
......@@ -913,8 +926,7 @@ panel_applet_load_list (AppletType type,
panel_applet_load_from_unique_id (type, client, profile, (char *) l->data, use_default);
g_free (temp_key);
g_slist_foreach (id_list, (GFunc) g_free, NULL);
g_slist_free (id_list);
panel_g_slist_deep_free (id_list);
}
void
......@@ -992,8 +1004,7 @@ panel_applet_save_to_gconf (AppletInfo *applet_info)
}
g_free (temp_key);
g_slist_foreach (id_list, (GFunc) g_free, NULL);
g_slist_free (id_list);
panel_g_slist_deep_free (id_list);
temp_key = panel_applet_get_full_gconf_key (applet_info->type, profile,
applet_info->gconf_key, "object-type", FALSE);
......@@ -1120,11 +1131,10 @@ panel_applet_register (GtkWidget *applet,
break;
if(!list) {
/*can't put it anywhere, clean up*/
gtk_widget_destroy(applet);
info->widget = NULL;
panel_applet_clean(info);
gtk_widget_destroy (applet);
panel_applet_clean (info);
g_warning(_("Can't find an empty spot"));
g_free (info);
return NULL;
}
panel = PANEL_WIDGET(list->data);
......@@ -1136,9 +1146,9 @@ panel_applet_register (GtkWidget *applet,
G_CALLBACK(applet_button_press),
info);
g_signal_connect(G_OBJECT(applet), "destroy",
G_CALLBACK(applet_destroy),
info);
g_signal_connect (G_OBJECT (applet), "destroy",
G_CALLBACK (applet_destroy),
info);
gtk_widget_show_all(applet);
......
......@@ -45,6 +45,8 @@ typedef struct {
gpointer data;
GDestroyNotify data_destroy;
guint remove_idle;
char *gconf_key;
} AppletInfo;
......
......@@ -100,8 +100,7 @@ fill_executables (void)
const char *path;
char **pathv;
g_list_foreach (executables, (GFunc) g_free, NULL);
g_list_free (executables);
panel_g_list_deep_free (executables);
executables = NULL;
path = g_getenv ("PATH");
......@@ -133,8 +132,7 @@ static void
kill_completion (void)
{
if (executables != NULL) {
g_list_foreach (executables, (GFunc) g_free, NULL);
g_list_free (executables);
panel_g_list_deep_free (executables);
executables = NULL;
}
......@@ -163,8 +161,7 @@ get_environment (int *argc, char ***argv, int *envc, char ***envv)
}
if (moveby == *argc) {
g_list_foreach (envar, (GFunc) g_free, NULL);
g_list_free (envar);
panel_g_list_deep_free (envar);
return;
}
......
......@@ -288,8 +288,7 @@ fr_free (FileRec *fr, gboolean free_fr)
dr->recs = NULL;
if (dr->tryexecs != NULL) {
g_slist_foreach (dr->tryexecs, (GFunc) g_free, NULL);
g_slist_free (dr->tryexecs);
panel_g_slist_deep_free (dr->tryexecs);
dr->tryexecs = NULL;
}
dir_list = g_slist_remove (dir_list, fr);
......
......@@ -1903,8 +1903,7 @@ check_and_reread_applet (Menu *menu)
}
add_menu_widget (menu, NULL, dirlist, TRUE);
g_slist_foreach (dirlist, (GFunc)g_free, NULL);
g_slist_free (dirlist);
panel_g_slist_deep_free (dirlist);
}
}
}
......
......@@ -95,7 +95,9 @@ popup_handle_remove (BonoboUIComponent *uic,
PanelAppletFrame *frame,
const gchar *verbname)
{
panel_applet_clean (frame->priv->applet_info);
AppletInfo *info = frame->priv->applet_info;
frame->priv->applet_info = NULL;
panel_applet_clean (info);
}
static void
......@@ -302,6 +304,7 @@ panel_applet_frame_finalize (GObject *object)
PanelAppletFrame *frame = PANEL_APPLET_FRAME (object);
g_free (frame->priv->iid);
frame->priv->iid = NULL;
g_free (frame->priv);
frame->priv = NULL;
......
......@@ -1241,6 +1241,28 @@ panel_ensure_dir (const char *dirname)
return TRUE;
}
void
panel_g_list_deep_free (GList *list)
{
GList *li;
for (li = list; li != NULL; li = li->next) {
g_free (li->data);
li->data = NULL;
}
g_list_free (list);
}
void
panel_g_slist_deep_free (GSList *list)
{
GSList *li;
for (li = list; li != NULL; li = li->next) {
g_free (li->data);
li->data = NULL;
}
g_slist_free (list);
}
#if 0
/* hmmm, we need to use this I think to add a battery applet
* -George */
......
......@@ -44,6 +44,9 @@ GList * my_g_list_resort_item (GList *list,
gpointer data,
GCompareFunc func);
void panel_g_list_deep_free (GList *list);
void panel_g_slist_deep_free (GSList *list);
void set_frame_colors (PanelWidget *panel,
GtkWidget *frame,
GtkWidget *but1,
......@@ -111,7 +114,6 @@ void panel_signal_connect_object_while_alive (GObject *object,
GCallback func,
GObject *alive_object);
gboolean panel_ensure_dir (const char *dirname);
/* GnomeVFS reading utils */
......
......@@ -2599,8 +2599,7 @@ panel_session_init_panels(void)
gtk_widget_show (panel);
}
g_slist_foreach (panel_ids, (GFunc)g_free, NULL);
g_slist_free (panel_ids);
panel_g_slist_deep_free (panel_ids);
}
static void
......@@ -2706,8 +2705,7 @@ panel_session_save_panel (PanelData *pd)
}
g_free (panel_id_key);
g_slist_foreach (panel_id_list, (GFunc)g_free, NULL);
g_slist_free (panel_id_list);
panel_g_slist_deep_free (panel_id_list);
panel_gconf_panel_profile_set_string (panel_profile,
panel->unique_id,
......@@ -2854,8 +2852,7 @@ panel_session_remove_panel_from_config (PanelWidget *panel) {
new_panel_ids,
NULL);
if (new_panel_ids != NULL) {
g_slist_foreach (new_panel_ids, (GFunc) g_free, NULL);
g_slist_free (new_panel_ids);
panel_g_slist_deep_free (new_panel_ids);
}
gconf_client_suggest_sync (panel_gconf_get_client (), NULL);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment