From 0c9ee243494707f2ab0783c33e9d71a0ee211de6 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Wed, 25 Apr 2012 10:11:47 +0000 Subject: [PATCH] put cleanup stuff into a separate fct --- src/main.c | 71 ++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/src/main.c b/src/main.c index c09380b..c42f18e 100644 --- a/src/main.c +++ b/src/main.c @@ -236,7 +236,7 @@ gboolean ui_refresh_thread(gpointer data) return ret; } -void cb_alarm_raised(struct psensor *sensor, void *data) +static void cb_alarm_raised(struct psensor *sensor, void *data) { #ifdef HAVE_LIBNOTIFY if (sensor->enabled) @@ -395,6 +395,43 @@ static void activate(GApplication *application, ui_window_show((struct ui_psensor *)data); } +/* + * Release memory for Valgrind. + */ +static void cleanup(struct ui_psensor *ui) +{ + g_mutex_lock(ui->sensors_mutex); + + psensor_cleanup(); + +#ifdef HAVE_NVIDIA + nvidia_cleanup(); +#endif +#ifdef HAVE_LIBATIADL + amd_cleanup(); +#endif +#ifdef HAVE_REMOTE_SUPPORT + rsensor_cleanup(); +#endif + + psensor_list_free(ui->sensors); + ui->sensors = NULL; + +#if defined(HAVE_APPINDICATOR) || defined(HAVE_APPINDICATOR_029) + ui_appindicator_cleanup(); +#endif + + ui_status_cleanup(); + + g_mutex_unlock(ui->sensors_mutex); + + config_cleanup(); + + log_debug("Cleanup done, closing log"); + + log_close(); +} + int main(int argc, char **argv) { struct ui_psensor ui; @@ -555,37 +592,7 @@ int main(int argc, char **argv) gtk_main(); log_debug("Quitting..."); - - g_mutex_lock(ui.sensors_mutex); - - psensor_cleanup(); - -#ifdef HAVE_NVIDIA - nvidia_cleanup(); -#endif -#ifdef HAVE_LIBATIADL - amd_cleanup(); -#endif -#ifdef HAVE_REMOTE_SUPPORT - rsensor_cleanup(); -#endif - - psensor_list_free(ui.sensors); - ui.sensors = NULL; - -#if defined(HAVE_APPINDICATOR) || defined(HAVE_APPINDICATOR_029) - ui_appindicator_cleanup(); -#endif - - ui_status_cleanup(); - - g_mutex_unlock(ui.sensors_mutex); - - config_cleanup(); - - log_debug("Cleanup done, closing log"); - - log_close(); + cleanup(&ui); return 0; } -- 2.7.4