[gjs/halfline/debug-metrics: 3/4] gi: Name slice allocations




commit 10d857f0442043ff490822c34530250616210ed7
Author: Ray Strode <rstrode redhat com>
Date:   Wed Dec 15 10:53:54 2021 -0500

    gi: Name slice allocations
    
    When tracking slice allocations, it's important they have a name, so
    the bookkeeping doesn't lump them with other allocations or lose track
    of them.

 gi/boxed.cpp    | 4 ++--
 gi/function.cpp | 7 +++----
 2 files changed, 5 insertions(+), 6 deletions(-)
---
diff --git a/gi/boxed.cpp b/gi/boxed.cpp
index 231bd0f4..92cfa183 100644
--- a/gi/boxed.cpp
+++ b/gi/boxed.cpp
@@ -213,7 +213,7 @@ boxed_new_direct(Boxed       *priv)
 {
     g_assert(priv->can_allocate_directly);
 
-    priv->gboxed = g_slice_alloc0(g_struct_info_get_size (priv->info));
+    priv->gboxed = g_slice_alloc0_with_name(g_struct_info_get_size (priv->info), g_base_info_get_name 
((GIBaseInfo *)priv->info));
     priv->allocated_directly = true;
 
     gjs_debug_lifecycle(GJS_DEBUG_GBOXED,
@@ -485,7 +485,7 @@ boxed_finalize(JSFreeOp *fop,
 
     if (priv->gboxed && !priv->not_owning_gboxed) {
         if (priv->allocated_directly) {
-            g_slice_free1(g_struct_info_get_size (priv->info), priv->gboxed);
+            g_slice_free1_with_name(g_struct_info_get_size (priv->info), priv->gboxed, g_base_info_get_name 
((GIBaseInfo *)priv->info));
         } else {
             if (g_type_is_a (priv->gtype, G_TYPE_BOXED))
                 g_boxed_free (priv->gtype,  priv->gboxed);
diff --git a/gi/function.cpp b/gi/function.cpp
index 94129802..b349d52b 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -901,12 +901,11 @@ gjs_invoke_c_function(JSContext                             *context,
                         failed = true;
                     }
 
-                    g_base_info_unref((GIBaseInfo*)interface_info);
-
                     if (!failed) {
-                        in_arg_cvalues[c_arg_pos].v_pointer = g_slice_alloc0(size);
+                        in_arg_cvalues[c_arg_pos].v_pointer = g_slice_alloc0_with_name(size, 
g_base_info_get_name ((GIBaseInfo*)interface_info));
                         out_arg_cvalues[c_arg_pos].v_pointer = in_arg_cvalues[c_arg_pos].v_pointer;
                     }
+                    g_base_info_unref((GIBaseInfo*)interface_info);
                 } else {
                     failed = true;
                 }
@@ -1335,7 +1334,7 @@ release:
                     g_assert_not_reached();
                 }
 
-                g_slice_free1(size, out_arg_cvalues[c_arg_pos].v_pointer);
+                g_slice_free1_with_name(size, out_arg_cvalues[c_arg_pos].v_pointer, g_base_info_get_name 
((GIBaseInfo *) interface_info));
                 g_base_info_unref((GIBaseInfo*)interface_info);
             }
 


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