1 fix crash in gui, rhbz#578276
2 https://bugzilla.redhat.com/show_bug.cgi?id=578276
4 --- apcupsd-3.14.9/src/gapcmon/gapcmon.c.timeout 2008-09-16 06:58:20.000000000 +0200
5 +++ apcupsd-3.14.9/src/gapcmon/gapcmon.c 2011-10-12 20:10:52.986362156 +0200
6 @@ -179,6 +179,54 @@ struct hostent * gethostname_re
8 static gboolean lg_graph_debug = FALSE;
10 +static GSList *timeout_list = NULL;
12 +static inline timeout_t * new_timeout(guint id, timeout_type_t type, void *data) {
13 + timeout_t *timeout = (timeout_t *) malloc(sizeof(timeout_t));
16 + timeout->type = type;
17 + timeout->data = data;
21 +/* callback will check if timeout is associated with window
22 + * which is about to be destroyed and it will call g_source_remove
23 + * in order to prevent the callback associated with timeout to be executed
25 +static void remove_timeout(gpointer tmo, gpointer data) {
26 + timeout_t * timeout = (timeout_t *) tmo;
27 + PGAPC_MONITOR monitor = (PGAPC_MONITOR) data;
28 + int delete_timeout = 0;
30 + if (timeout == NULL) {
34 + switch (timeout->type) {
36 + if (timeout->data == (void *) monitor->phs.plg) {
41 + if (timeout->data == (void *) monitor) {
47 + if (timeout->data == (void *) &(monitor->phs)) {
53 + if (delete_timeout) {
54 + g_source_remove(timeout->id);
55 + timeout_list = g_slist_remove(timeout_list, (gconstpointer) timeout);
59 /* ************************************************************************* */
61 @@ -1376,8 +1424,8 @@ static gint lg_graph_configure_event_cb
62 plg->x_range.i_minor_inc = plg->plot_box.width / plg->x_range.i_num_minor;
63 plg->x_range.i_major_inc = plg->plot_box.width / plg->x_range.i_num_major;
65 - g_timeout_add (250, (GSourceFunc) lg_graph_draw, plg);
67 + guint tid = g_timeout_add (250, (GSourceFunc) lg_graph_draw, plg);
68 + timeout_list = g_slist_append(timeout_list, new_timeout(tid, GRAPH, (void *) plg));
72 @@ -1745,7 +1793,8 @@ static gboolean cb_monitor_automatic_ref
73 return FALSE; /* stop timers */
75 if (pm->b_timer_control) {
76 - g_timeout_add(100, (GSourceFunc) cb_monitor_refresh_control, pm);
77 + guint tid = g_timeout_add(100, (GSourceFunc) cb_monitor_refresh_control, pm);
78 + timeout_list = g_slist_append(timeout_list, new_timeout(tid, MONITOR, (void *) pm));
82 @@ -4543,9 +4592,9 @@ static void cb_monitor_interface_button_
85 g_async_queue_push(pm->q_network, pm);
86 - g_timeout_add(GAPC_REFRESH_FACTOR_ONE_TIME,
87 + guint tid = g_timeout_add(GAPC_REFRESH_FACTOR_ONE_TIME,
88 (GSourceFunc) cb_monitor_dedicated_one_time_refresh, pm);
90 + timeout_list = g_slist_append(timeout_list, new_timeout(tid, MONITOR, (void *) pm));
94 @@ -5174,6 +5223,9 @@ static void cb_monitor_interface_destroy
95 g_source_remove(pm->tid_automatic_refresh);
98 + /* iterate through list of timers and remove all timers associated with this monitor */
99 + g_slist_foreach(timeout_list, remove_timeout, (gpointer) pm);
101 if (pm->tid_thread_qwork != NULL) {
102 pm->b_thread_stop = TRUE;
103 g_async_queue_push(pm->q_network, pm);
104 @@ -5537,9 +5589,9 @@ static gint gapc_monitor_history_page(PG
106 /* collect one right away */
107 pphs->b_startup = TRUE;
108 - g_timeout_add((guint) (pm->d_refresh * GAPC_REFRESH_FACTOR_1K + 75),
109 + guint tid = g_timeout_add((guint) (pm->d_refresh * GAPC_REFRESH_FACTOR_1K + 75),
110 (GSourceFunc) cb_util_line_chart_refresh, pphs);
112 + timeout_list = g_slist_append(timeout_list, new_timeout(tid, HISTORY, (void *) pphs));
116 @@ -5565,7 +5617,8 @@ static gboolean cb_util_line_chart_refre
119 if (pm->b_graph_control) {
120 - g_timeout_add(100, (GSourceFunc) cb_util_line_chart_refresh_control, pm);
121 + guint tid = g_timeout_add(100, (GSourceFunc) cb_util_line_chart_refresh_control, pm);
122 + timeout_list = g_slist_append(timeout_list, new_timeout(tid, MONITOR, (void *) pm));
126 @@ -6392,6 +6445,7 @@ extern int main(int argc, char *argv[])
127 PGAPC_CONFIG pcfg = NULL;
128 GtkWidget *window = NULL;
130 + timeout_list = g_slist_alloc();
132 * Initialize GLib thread support, and GTK
134 @@ -6435,5 +6489,6 @@ extern int main(int argc, char *argv[])
138 + g_slist_free(timeout_list);
141 --- apcupsd-3.14.9/src/gapcmon/gapcmon.h 2011-10-12 20:12:54.584317583 +0200
142 +++ apcupsd-3.14.9/src/gapcmon/gapcmon.h.timeout 2011-10-12 20:14:10.965669911 +0200
143 @@ -403,6 +403,18 @@ typedef struct _System_Control_Data {
145 } GAPC_CONFIG, *PGAPC_CONFIG;
155 + timeout_type_t type;
159 /* ************************************************************************* */
161 #define GAPC_GLOSSARY "<span size=\"xx-large\"><b>GAPCMON</b></span>\n \