mirror of
https://github.com/ruby/ruby.git
synced 2026-07-31 09:25:15 +08:00
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
This commit is contained in:
parent
7e31d3c022
commit
a4ca3de38e
@ -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) {
|
||||
|
||||
@ -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"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user