app: avoid potential use-after-free during GimpDashboard destruction

... by making sure that the sampling thread quits before the meters
are destroyed, and before clearing the low-swap-warning idle
source.
This commit is contained in:
Ell 2017-12-25 13:10:47 -05:00
parent 3837cccb48
commit 822386f551
1 changed files with 21 additions and 11 deletions

View File

@ -59,6 +59,7 @@
static void gimp_dashboard_docked_iface_init (GimpDockedInterface *iface);
static void gimp_dashboard_dispose (GObject *object);
static void gimp_dashboard_finalize (GObject *object);
static void gimp_dashboard_map (GtkWidget *widget);
@ -99,6 +100,7 @@ gimp_dashboard_class_init (GimpDashboardClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->dispose = gimp_dashboard_dispose;
object_class->finalize = gimp_dashboard_finalize;
widget_class->map = gimp_dashboard_map;
@ -313,10 +315,22 @@ gimp_dashboard_docked_iface_init (GimpDockedInterface *iface)
}
static void
gimp_dashboard_finalize (GObject *object)
gimp_dashboard_dispose (GObject *object)
{
GimpDashboard *dashboard = GIMP_DASHBOARD (object);
if (dashboard->thread)
{
g_mutex_lock (&dashboard->mutex);
dashboard->quit = TRUE;
g_cond_signal (&dashboard->cond);
g_mutex_unlock (&dashboard->mutex);
g_clear_pointer (&dashboard->thread, g_thread_join);
}
if (dashboard->timeout_id)
{
g_source_remove (dashboard->timeout_id);
@ -329,17 +343,13 @@ gimp_dashboard_finalize (GObject *object)
dashboard->low_swap_space_idle_id = 0;
}
if (dashboard->thread)
{
g_mutex_lock (&dashboard->mutex);
G_OBJECT_CLASS (parent_class)->dispose (object);
}
dashboard->quit = TRUE;
g_cond_signal (&dashboard->cond);
g_mutex_unlock (&dashboard->mutex);
g_clear_pointer (&dashboard->thread, g_thread_join);
}
static void
gimp_dashboard_finalize (GObject *object)
{
GimpDashboard *dashboard = GIMP_DASHBOARD (object);
g_mutex_clear (&dashboard->mutex);
g_cond_clear (&dashboard->cond);