[tepl] App: hold/release GApplication in signal handlers



commit 60373c616145e6a0ca37c1fb1c18b030f6489342
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Oct 14 14:15:25 2017 +0200

    App: hold/release GApplication in signal handlers
    
    That's a best-practice IIRC, to avoid a crash if the functions that we
    call inside the signal handler makes the application to quit.

 tepl/tepl-application.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/tepl/tepl-application.c b/tepl/tepl-application.c
index f62d10f..d21cae9 100644
--- a/tepl/tepl-application.c
+++ b/tepl/tepl-application.c
@@ -394,11 +394,13 @@ activate_cb (GApplication    *g_app,
        TeplAbstractFactory *factory;
        GtkApplicationWindow *main_window;
 
+       g_application_hold (g_app);
+
        factory = tepl_abstract_factory_get_singleton ();
        main_window = tepl_abstract_factory_create_main_window (factory, tepl_app->priv->gtk_app);
-       g_return_if_fail (main_window != NULL);
-
        gtk_widget_show (GTK_WIDGET (main_window));
+
+       g_application_release (g_app);
 }
 
 /**
@@ -444,6 +446,8 @@ open_cb (GApplication     *g_app,
                return;
        }
 
+       g_application_hold (g_app);
+
        main_window = tepl_application_get_active_main_window (tepl_app);
 
        if (main_window == NULL)
@@ -452,7 +456,12 @@ open_cb (GApplication     *g_app,
 
                factory = tepl_abstract_factory_get_singleton ();
                main_window = tepl_abstract_factory_create_main_window (factory, tepl_app->priv->gtk_app);
-               g_return_if_fail (main_window != NULL);
+
+               if (main_window == NULL)
+               {
+                       g_warn_if_reached ();
+                       goto out;
+               }
 
                gtk_widget_show (GTK_WIDGET (main_window));
        }
@@ -475,6 +484,9 @@ open_cb (GApplication     *g_app,
 
                tepl_application_window_open_file (tepl_window, cur_file, jump_to);
        }
+
+out:
+       g_application_release (g_app);
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]