[ruby-core:116388] [BUG] leak in deprecated Data_Make_Struct

I can't open new bug on Redmine due to TOTP so I'll post here. (I'm not going to run JS, view images, or deal with proprietary tools/services). I realize Data_Make_Struct is deprecated and I'm updating a gem to TypedData, there's likely old code which is affected by this leak. With the patch below to make data_spec.c use Data_Make_Struct, this script leaks: $LOAD_PATH << './spec/ruby/optional/capi/ext' require 'data_spec' loop { CApiAllocSpecs.Data_Make_Struct } I noticed this on Ruby 3.3 (32-bit x86) with `clogger' RubyGem, and also up to recent master commit c0cabc0a699b2c8b (Dump annotations on RubyVM::ISeq.disasm (#9667), 2024-01-23) --- Not sure how to write a Ruby spec for malloc memory leaks but I'm just a drive by contributor at this point. It takes me 2-3 hours to build and test Ruby on my old system so I don't feel like doing more. spec/ruby/optional/capi/ext/data_spec.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/ruby/optional/capi/ext/data_spec.c b/spec/ruby/optional/capi/ext/data_spec.c index ef069ef0ba..450eef6c76 100644 --- a/spec/ruby/optional/capi/ext/data_spec.c +++ b/spec/ruby/optional/capi/ext/data_spec.c @@ -24,6 +24,11 @@ VALUE sdaf_alloc_func(VALUE klass) { return Data_Wrap_Struct(klass, &sample_wrapped_struct_mark, &sample_wrapped_struct_free, bar); } +VALUE sdaf_make_struct(VALUE klass) { + struct sample_wrapped_struct* bar; + return Data_Make_Struct(klass, struct sample_wrapped_struct, sample_wrapped_struct_mark, RUBY_DEFAULT_FREE, bar); +} + VALUE sdaf_get_struct(VALUE self) { struct sample_wrapped_struct* bar; Data_Get_Struct(self, struct sample_wrapped_struct, bar); @@ -74,6 +79,7 @@ VALUE sws_rb_check_type(VALUE self, VALUE obj, VALUE other) { void Init_data_spec(void) { VALUE cls = rb_define_class("CApiAllocSpecs", rb_cObject); rb_define_alloc_func(cls, sdaf_alloc_func); + rb_define_singleton_method(cls, "Data_Make_Struct", sdaf_make_struct, 0); rb_define_method(cls, "wrapped_data", sdaf_get_struct, 0); cls = rb_define_class("CApiWrappedStructSpecs", rb_cObject); rb_define_method(cls, "wrap_struct", sws_wrap_struct, 1);
participants (1)
-
Eric Wong