[java-atk-wrapper] JNI: Add NULL check before referencing gobjects



commit 6fce7ec46060272bfe3b1a8d43741ba915b5ccf6
Author: Magdalen Berns <m berns thismagpie com>
Date:   Sun Mar 8 20:33:23 2015 +0000

    JNI: Add NULL check before referencing gobjects
    
    Bug: https://bugzilla.gnome.org/show_bug.cgi?id=745850

 jni/src/jawhypertext.c |    3 ++-
 jni/src/jawobject.c    |   17 ++++++++---------
 jni/src/jawtoplevel.c  |    3 ++-
 3 files changed, 12 insertions(+), 11 deletions(-)
---
diff --git a/jni/src/jawhypertext.c b/jni/src/jawhypertext.c
index d54c175..5622e82 100644
--- a/jni/src/jawhypertext.c
+++ b/jni/src/jawhypertext.c
@@ -50,7 +50,8 @@ static void
 link_destroy_notify (gpointer p)
 {
        JawHyperlink* jaw_hyperlink = (JawHyperlink*)p;
-       g_object_unref(G_OBJECT(jaw_hyperlink));
+       if(G_OBJECT(jaw_hyperlink) != NULL)
+               g_object_unref(G_OBJECT(jaw_hyperlink));
 }
 
 gpointer
diff --git a/jni/src/jawobject.c b/jni/src/jawobject.c
index 67b845a..1e97fdc 100644
--- a/jni/src/jawobject.c
+++ b/jni/src/jawobject.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include <atk/atk.h>
 #include <glib.h>
 #include "jawobject.h"
 #include "jawutil.h"
@@ -56,7 +57,7 @@ enum {
 
 static guint jaw_window_signals[TOTAL_SIGNAL] = { 0, };
 
-G_DEFINE_TYPE (JawObject, jaw_object, ATK_TYPE_OBJECT)
+G_DEFINE_TYPE (JawObject, jaw_object, ATK_TYPE_OBJECT);
 
 static void
 jaw_object_class_init (JawObjectClass *klass)
@@ -170,11 +171,8 @@ gpointer
 jaw_object_get_interface_data (JawObject *jaw_obj, guint iface)
 {
   JawObjectClass *klass = JAW_OBJECT_GET_CLASS(jaw_obj);
-
   if (klass->get_interface_data)
-  {
     return klass->get_interface_data(jaw_obj, iface);
-  }
 
   return NULL;
 }
@@ -218,18 +216,18 @@ jaw_object_finalize (GObject *gobject)
     (*jniEnv)->ReleaseStringUTFChars(jniEnv,
                                      jaw_obj->jstrDescription,
                                      atk_obj->description);
+
     (*jniEnv)->DeleteGlobalRef(jniEnv, jaw_obj->jstrDescription);
     jaw_obj->jstrDescription = NULL;
     atk_obj->description = NULL;
   }
 
-  if (jaw_obj->state_set != NULL)
+  if (G_OBJECT(jaw_obj->state_set) != NULL)
   {
     g_object_unref(G_OBJECT(jaw_obj->state_set));
+    /* Chain up to parent's finalize method */
+    G_OBJECT_CLASS(jaw_object_parent_class)->finalize(gobject);
   }
-
-  /* Chain up to parent's finalize method */
-  G_OBJECT_CLASS(jaw_object_parent_class)->finalize(gobject);
 }
 
 static const gchar*
@@ -401,7 +399,8 @@ jaw_object_ref_state_set (AtkObject *atk_obj)
     }
   }
 
-  g_object_ref(G_OBJECT(state_set));
+  if (G_OBJECT(state_set) != NULL)
+    g_object_ref(G_OBJECT(state_set));
 
   return state_set;
 }
diff --git a/jni/src/jawtoplevel.c b/jni/src/jawtoplevel.c
index 70c3355..db8de88 100644
--- a/jni/src/jawtoplevel.c
+++ b/jni/src/jawtoplevel.c
@@ -135,7 +135,8 @@ jaw_toplevel_ref_child (AtkObject *obj, gint i)
   JawToplevel *jaw_toplevel = JAW_TOPLEVEL(obj);
   AtkObject* child = (AtkObject*)g_list_nth_data(jaw_toplevel->windows, i);
 
-  g_object_ref(G_OBJECT(child));
+  if (G_OBJECT(child) != NULL)
+    g_object_ref(G_OBJECT(child));
 
   return child;
 }


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