[#116016] [Ruby master Bug#20150] Memory leak in grapheme clusters — "peterzhu2118 (Peter Zhu) via ruby-core" <ruby-core@...>
Issue #20150 has been reported by peterzhu2118 (Peter Zhu).
7 messages
2024/01/04
[#116382] [Ruby master Feature#20205] Enable `frozen_string_literal` by default — "byroot (Jean Boussier) via ruby-core" <ruby-core@...>
Issue #20205 has been reported by byroot (Jean Boussier).
77 messages
2024/01/23
[ruby-core:116388] [BUG] leak in deprecated Data_Make_Struct
From:
Eric Wong via ruby-core <ruby-core@...>
Date:
2024-01-24 00:24:23 UTC
List:
ruby-core #116388
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);
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/