[gjs/gbsneto/fundamental-fixes] fundamental: Check if gtype is valid before using it



commit 41634c30bf990ba1b6ba7d359f24ffb473e52e41
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Oct 9 19:52:39 2018 -0300

    fundamental: Check if gtype is valid before using it
    
    Not a big deal, but found this bug while investigating some
    problems that arose from https://gitlab.gnome.org/GNOME/mutter/merge_requests/260.
    
    We should check if the GType is valid before using it, not
    after.

 gi/fundamental.cpp | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
---
diff --git a/gi/fundamental.cpp b/gi/fundamental.cpp
index a5e1ce95..5b0463d8 100644
--- a/gi/fundamental.cpp
+++ b/gi/fundamental.cpp
@@ -623,23 +623,16 @@ static JSObject*
 gjs_lookup_fundamental_prototype_from_gtype(JSContext *context,
                                             GType      gtype)
 {
-    GIObjectInfo *info;
-    JSObject *proto;
+    GjsAutoInfo<GIObjectInfo> info;
 
     /* A given gtype might not have any definition in the introspection
      * data. If that's the case, try to look for a definition of any of the
      * parent type. */
-    while ((info = (GIObjectInfo *)
-            g_irepository_find_by_gtype(g_irepository_get_default(),
-                                        gtype)) == NULL &&
-           gtype != G_TYPE_INVALID)
+    while (gtype != G_TYPE_INVALID &&
+           !(info = g_irepository_find_by_gtype(nullptr, gtype)))
         gtype = g_type_parent(gtype);
 
-    proto = gjs_lookup_fundamental_prototype(context, info, gtype);
-    if (info)
-        g_base_info_unref((GIBaseInfo*)info);
-
-    return proto;
+    return gjs_lookup_fundamental_prototype(context, info, gtype);
 }
 
 bool


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