From a4ca3de38e8910d7fc8968036157c08cb2604af5 Mon Sep 17 00:00:00 2001 From: nagachika Date: Sat, 11 Oct 2025 18:28:36 +0900 Subject: merge revision(s) 07b59eee6aa120537d7d72422327cc7b855e9400: [PATCH] Fix memory leak when load_from_binary raises ibf_load_code will leak memory allocated for the code if an exception is raised. The following script reproduces the leak: bin = RubyVM::InstructionSequence.of(1.method(:abs)).to_binary 10.times do 100_000.times do RubyVM::InstructionSequence.load_from_binary(bin) rescue ArgumentError end puts `ps -o rss= -p #{$$}` end Before: 18004 23380 28756 34260 39892 45396 50772 55892 61012 66132 After: 12536 12920 13304 13688 14072 14456 14840 15352 15608 15864 --- compile.c | 4 +++- version.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/compile.c b/compile.c index 0ed85a8109..504afbc592 100644 --- a/compile.c +++ b/compile.c @@ -11825,6 +11825,9 @@ ibf_load_code(const struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t bytecod struct rb_call_data *cd_entries = load_body->call_data; int ic_index = 0; + load_body->iseq_encoded = code; + load_body->iseq_size = 0; + iseq_bits_t * mark_offset_bits; iseq_bits_t tmp[1] = {0}; @@ -11956,7 +11959,6 @@ ibf_load_code(const struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t bytecod } } - load_body->iseq_encoded = code; load_body->iseq_size = code_index; if (ISEQ_MBITS_BUFLEN(load_body->iseq_size) == 1) { diff --git a/version.h b/version.h index 2b6ee860aa..e2eacfaea4 100644 --- a/version.h +++ b/version.h @@ -11,7 +11,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 9 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 179 +#define RUBY_PATCHLEVEL 180 #include "ruby/version.h" #include "ruby/internal/abi.h" -- cgit v1.2.3