[gtk+] application: don't unconditionally unref the GMenuModel in getters



commit 157d9271fa64074a3e1d92994adbcc073d4bc6ce
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Wed Dec 21 12:20:15 2011 +0100

    application: don't unconditionally unref the GMenuModel in getters
    
    Both the app-menu and menubar models can be NULL, so we shouldn't
    blindly unref them, since g_object_unref() doesn't cope with NULL
    pointers.

 gtk/gtkapplication.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkapplication.c b/gtk/gtkapplication.c
index 5f428e2..08d0117 100644
--- a/gtk/gtkapplication.c
+++ b/gtk/gtkapplication.c
@@ -792,10 +792,12 @@ gtk_application_set_app_menu (GtkApplication *application,
 GMenuModel *
 gtk_application_get_app_menu (GtkApplication *application)
 {
-  GMenuModel *app_menu;
+  GMenuModel *app_menu = NULL;
 
   g_object_get (application, "app-menu", &app_menu, NULL);
-  g_object_unref (app_menu);
+
+  if (app_menu)
+    g_object_unref (app_menu);
 
   return app_menu;
 }
@@ -840,10 +842,12 @@ gtk_application_set_menubar (GtkApplication *application,
 GMenuModel *
 gtk_application_get_menubar (GtkApplication *application)
 {
-  GMenuModel *menubar;
+  GMenuModel *menubar = NULL;
 
   g_object_get (application, "menubar", &menubar, NULL);
-  g_object_unref (menubar);
+
+  if (menubar)
+    g_object_unref (menubar);
 
   return menubar;
 }



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