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




commit 718c9c29a31f2ef4d3852edc2a420a8869f6d166
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 1ec48c948..54a491c5e 100644
--- a/gi/arg-cache.cpp
+++ b/gi/arg-cache.cpp
@@ -262,9 +262,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 &&
@@ -2178,8 +2177,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]