[gjs/wip/ptomato/786668: 1/6] arg: Fix memory leaks



commit cc4187ed14170da358181065ff5fd95693f9244b
Author: Philip Chimento <philip endlessm com>
Date:   Tue Aug 22 09:51:52 2017 -0700

    arg: Fix memory leaks
    
    Caught with Valgrind.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786668

 gi/arg.cpp |   46 +++++++++++++++++++++++-----------------------
 1 files changed, 23 insertions(+), 23 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 5cb4a99..5f4dc59 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -1900,9 +1900,6 @@ gjs_value_to_g_argument(JSContext      *context,
         gpointer data;
         gsize length;
         GIArrayType array_type = g_type_info_get_array_type(type_info);
-        GITypeInfo *param_info;
-
-        param_info = g_type_info_get_param_type(type_info, 0);
 
         /* First, let's handle the case where we're passed an instance
          * of our own byteArray class.
@@ -1931,6 +1928,7 @@ gjs_value_to_g_argument(JSContext      *context,
             break;
         }
 
+        GITypeInfo *param_info = g_type_info_get_param_type(type_info, 0);
         if (array_type == GI_ARRAY_TYPE_C) {
             arg->v_pointer = data;
         } else if (array_type == GI_ARRAY_TYPE_ARRAY) {
@@ -2287,33 +2285,35 @@ gjs_array_from_carray_internal (JSContext             *context,
           ITERATE(double);
           break;
         case GI_TYPE_TAG_INTERFACE: {
-          GIBaseInfo *interface_info;
-          GIInfoType info_type;
+            GIBaseInfo *interface_info;
+            GIInfoType info_type;
 
-          interface_info = g_type_info_get_interface (param_info);
-          info_type = g_base_info_get_type (interface_info);
+            interface_info = g_type_info_get_interface (param_info);
+            info_type = g_base_info_get_type (interface_info);
 
-          if ((info_type == GI_INFO_TYPE_STRUCT ||
-               info_type == GI_INFO_TYPE_UNION) &&
-              !g_type_info_is_pointer (param_info)) {
-              gsize struct_size;
+            if ((info_type == GI_INFO_TYPE_STRUCT ||
+                 info_type == GI_INFO_TYPE_UNION) &&
+                !g_type_info_is_pointer (param_info)) {
+                gsize struct_size;
 
-              if (info_type == GI_INFO_TYPE_UNION)
-                  struct_size = g_union_info_get_size ((GIUnionInfo*)interface_info);
-              else
-                  struct_size = g_struct_info_get_size ((GIStructInfo*)interface_info);
+                if (info_type == GI_INFO_TYPE_UNION)
+                    struct_size = g_union_info_get_size ((GIUnionInfo*)interface_info);
+                else
+                    struct_size = g_struct_info_get_size ((GIStructInfo*)interface_info);
 
-              for (i = 0; i < length; i++) {
-                  arg.v_pointer = ((char*)array) + (struct_size * i);
+                for (i = 0; i < length; i++) {
+                    arg.v_pointer = ((char*)array) + (struct_size * i);
 
-                  if (!gjs_value_from_g_argument(context, elems[i], param_info,
-                                                 &arg, true))
-                      return false;
-              }
+                    if (!gjs_value_from_g_argument(context, elems[i], param_info,
+                                                   &arg, true))
+                        return false;
+                }
 
-              break;
-          }
+                g_base_info_unref(interface_info);
+                break;
+            }
 
+            g_base_info_unref(interface_info);
         }
         /* fallthrough */
         case GI_TYPE_TAG_GTYPE:


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