From 8b99c971ec7451068f8dece57ff31f1c629ffdaa Mon Sep 17 00:00:00 2001
From: Kouhei Sutou <kou@clear-code.com>
Date: Fri, 1 Feb 2019 06:22:35 +0900
Subject: [PATCH 5/5] gi: fix a memory leak for module function with callback
case
We can assume that the pango_cairo_context_set_shape_renderer()'s
first argument (Pango::Context) is suitable for owner of the callback.
GitHub: fix #1270
Reported by Izumi Tsutsui. Thanks!!!
---
.../ext/gobject-introspection/rb-gi-function-info.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/gobject-introspection/ext/gobject-introspection/rb-gi-function-info.c b/gobject-introspection/ext/gobject-introspection/rb-gi-function-info.c
index 33cee6644..0a0bc917b 100644
--- a/gobject-introspection/ext/gobject-introspection/rb-gi-function-info.c
+++ b/gobject-introspection/ext/gobject-introspection/rb-gi-function-info.c
@@ -1174,6 +1174,16 @@ in_callback_argument_from_ruby(RBGIArgMetadata *metadata,
if (NIL_P(mGLibObject)) {
mGLibObject = rb_const_get(mGLib, rb_intern("Object"));
}
+ if (NIL_P(rb_owner)) {
+ /* Module function case. */
+ VALUE rb_first_argument = rb_ary_entry(rb_arguments, 0);
+ if (rb_obj_is_kind_of(rb_first_argument, mGLibObject)) {
+ /* If the first argument of the module function call is
+ GObject, it's suitable for owner.
+ For example: pango_cairo_context_set_shape_renderer() */
+ rb_owner = rb_first_argument;
+ }
+ }
if (rb_obj_is_kind_of(rb_owner, mGLibObject)) {
rbgobj_object_add_relative(rb_owner, callback_data->rb_callback);
callback_data->owner = RVAL2GOBJ(rb_owner);
--
2.20.1