[gjs/gnome-42] arg-cache: Do not leak an interface info structures on Callbacks



commit 344a3c9c250346ed6178f6a62792520852f39993
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Thu Jun 2 01:57:38 2022 +0200

    arg-cache: Do not leak an interface info structures on Callbacks
    
    The cache is leaking the InterfaceInfo for each callback we pass as
    BaseInfo is implicitly adding a new reference, but in the CallbackIn
    case we were getting the interface from the type info, ignoring its
    transfer-full return type.
    
    To avoid this, just re-use the interface info we already got at
    initialization time, removing the uneeded function call and fixing
    the extra reference.

 gi/arg-cache.cpp | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
---
diff --git a/gi/arg-cache.cpp b/gi/arg-cache.cpp
index 83c4ad4da..f17062676 100644
--- a/gi/arg-cache.cpp
+++ b/gi/arg-cache.cpp
@@ -259,9 +259,8 @@ struct RegisteredInterface : BaseInfo {
 };
 
 struct Callback : Nullable, BaseInfo {
-    explicit Callback(GITypeInfo* type_info)
-        : BaseInfo(g_type_info_get_interface(type_info)),
-          m_scope(GI_SCOPE_TYPE_INVALID) {}
+    explicit Callback(GIInterfaceInfo* info)
+        : BaseInfo(info), m_scope(GI_SCOPE_TYPE_INVALID) {}
 
     inline void set_callback_destroy_pos(int pos) {
         g_assert(pos <= Argument::MAX_ARGS &&
@@ -2171,8 +2170,8 @@ void ArgsCache::build_arg(uint8_t gi_index, GIDirection direction,
                     common_args, DESTROY_NOTIFY_NO_CALLBACK);
                 *inc_counter_out = false;
             } else {
-                auto* gjs_arg =
-                    set_argument_auto<Arg::CallbackIn>(common_args, &type_info);
+                auto* gjs_arg = set_argument_auto<Arg::CallbackIn>(
+                    common_args, interface_info);
 
                 int destroy_pos = g_arg_info_get_destroy(arg);
                 int closure_pos = g_arg_info_get_closure(arg);


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