Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ releases.
* test-unit 3.7.7
* rss 0.3.2
* net-imap 0.6.2
* rbs 3.10.2
* rbs 3.10.3
* typeprof 0.31.1
* debug 1.11.1
* mutex_m 0.3.0
* resolv-replace 0.2.0
* syslog 0.4.0
* repl_type_completor 0.1.13
* rdoc 7.1.0

### RubyGems and Bundler
Expand Down
7 changes: 4 additions & 3 deletions bignum.c
Original file line number Diff line number Diff line change
Expand Up @@ -3036,20 +3036,21 @@ rb_big_realloc(VALUE big, size_t len)
else {
if (len <= embed_capa) {
ds = RBIGNUM(big)->as.heap.digits;
size_t old_len = RBIGNUM(big)->as.heap.len;
FL_SET_RAW(big, BIGNUM_EMBED_FLAG);
BIGNUM_SET_LEN(big, len);
(void)VALGRIND_MAKE_MEM_UNDEFINED((void*)RBIGNUM(big)->as.ary, embed_capa * sizeof(BDIGIT));
if (ds) {
MEMCPY(RBIGNUM(big)->as.ary, ds, BDIGIT, len);
xfree(ds);
SIZED_FREE_N(ds, old_len);
}
}
else {
if (BIGNUM_LEN(big) == 0) {
RBIGNUM(big)->as.heap.digits = ALLOC_N(BDIGIT, len);
}
else if (BIGNUM_LEN(big) < len) {
REALLOC_N(RBIGNUM(big)->as.heap.digits, BDIGIT, len);
else if (BIGNUM_LEN(big) != len) {
SIZED_REALLOC_N(RBIGNUM(big)->as.heap.digits, BDIGIT, len, BIGNUM_LEN(big));
}
}
}
Expand Down
21 changes: 13 additions & 8 deletions class.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
static enum rb_id_table_iterator_result
cvar_table_free_i(VALUE value, void *ctx)
{
xfree((void *)value);
struct rb_cvar_class_tbl_entry *entry = (struct rb_cvar_class_tbl_entry *)value;
SIZED_FREE(entry);
return ID_TABLE_CONTINUE;
}

Expand Down Expand Up @@ -118,11 +119,15 @@ rb_class_classext_free(VALUE klass, rb_classext_t *ext, bool is_prime)

if (RCLASSEXT_SUPERCLASSES_WITH_SELF(ext)) {
RUBY_ASSERT(is_prime); // superclasses should only be used on prime
xfree(RCLASSEXT_SUPERCLASSES(ext));
size_t depth = RCLASSEXT_SUPERCLASS_DEPTH(ext);
if (depth != RCLASS_MAX_SUPERCLASS_DEPTH) {
depth++;
}
SIZED_FREE_N(RCLASSEXT_SUPERCLASSES(ext), depth);
}

if (!is_prime) { // the prime classext will be freed with RClass
xfree(ext);
SIZED_FREE(ext);
}
}

Expand All @@ -141,7 +146,7 @@ rb_iclass_classext_free(VALUE klass, rb_classext_t *ext, bool is_prime)
rb_class_classext_free_subclasses(ext, klass, false);

if (!is_prime) { // the prime classext will be freed with RClass
xfree(ext);
SIZED_FREE(ext);
}
}

Expand All @@ -159,7 +164,7 @@ iclass_free_orphan_classext(VALUE klass, rb_classext_t *ext)

rb_class_classext_free_subclasses(ext, klass, true); // replacing this classext with a newer one

xfree(ext);
SIZED_FREE(ext);
}

struct rb_class_set_box_classext_args {
Expand Down Expand Up @@ -655,7 +660,7 @@ remove_class_from_subclasses(struct st_table *tbl, VALUE box_id, VALUE klass)
}
}

xfree(entry);
SIZED_FREE(entry);

break;
}
Expand Down Expand Up @@ -688,15 +693,15 @@ rb_class_classext_free_subclasses(rb_classext_t *ext, VALUE klass, bool replacin

while (entry) {
next = entry->next;
xfree(entry);
SIZED_FREE(entry);
entry = next;
}
VM_ASSERT(
rb_box_subclasses_ref_count(anchor->box_subclasses) > 0,
"box_subclasses refcount (%p) %ld", anchor->box_subclasses, rb_box_subclasses_ref_count(anchor->box_subclasses));
st_delete(tbl, &box_id, NULL);
rb_box_subclasses_ref_dec(anchor->box_subclasses);
xfree(anchor);
SIZED_FREE(anchor);

if (RCLASSEXT_BOX_SUPER_SUBCLASSES(ext)) {
rb_box_subclasses_t *box_sub = RCLASSEXT_BOX_SUPER_SUBCLASSES(ext);
Expand Down
38 changes: 22 additions & 16 deletions compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,7 @@ iseq_setup(rb_iseq_t *iseq, LINK_ANCHOR *const anchor)
debugs("[compile step 6.1 (remove unused catch tables)] \n");
RUBY_ASSERT(ISEQ_COMPILE_DATA(iseq));
if (!ISEQ_COMPILE_DATA(iseq)->catch_except_p && ISEQ_BODY(iseq)->catch_table) {
xfree(ISEQ_BODY(iseq)->catch_table);
ruby_sized_xfree(ISEQ_BODY(iseq)->catch_table, iseq_catch_table_bytes(ISEQ_BODY(iseq)->catch_table->size));
ISEQ_BODY(iseq)->catch_table = NULL;
}

Expand Down Expand Up @@ -2398,8 +2398,8 @@ get_cvar_ic_value(rb_iseq_t *iseq,ID id)
dump_disasm_list_with_cursor(FIRST_ELEMENT(anchor), list, dest)

#define BADINSN_ERROR \
(xfree(generated_iseq), \
xfree(insns_info), \
(SIZED_FREE_N(generated_iseq, generated_iseq_size), \
SIZED_FREE_N(insns_info, insns_info_size), \
BADINSN_DUMP(anchor, list, NULL), \
COMPILE_ERROR)

Expand Down Expand Up @@ -2665,8 +2665,13 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor)
}

/* make instruction sequence */
const int generated_iseq_size = code_index;
generated_iseq = ALLOC_N(VALUE, code_index);

const int insns_info_size = insn_num;
insns_info = ALLOC_N(struct iseq_insn_info_entry, insn_num);

const int positions_size = insn_num;
positions = ALLOC_N(unsigned int, insn_num);
if (ISEQ_IS_SIZE(body)) {
body->is_entries = ZALLOC_N(union iseq_inline_storage_entry, ISEQ_IS_SIZE(body));
Expand All @@ -2693,12 +2698,13 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor)

bool needs_bitmap = false;

if (ISEQ_MBITS_BUFLEN(code_index) == 1) {
const size_t mark_offset_bits_size = ISEQ_MBITS_BUFLEN(code_index);
if (mark_offset_bits_size == 1) {
mark_offset_bits = &ISEQ_COMPILE_DATA(iseq)->mark_bits.single;
ISEQ_COMPILE_DATA(iseq)->is_single_mark_bit = true;
}
else {
mark_offset_bits = ZALLOC_N(iseq_bits_t, ISEQ_MBITS_BUFLEN(code_index));
mark_offset_bits = ZALLOC_N(iseq_bits_t, mark_offset_bits_size);
ISEQ_COMPILE_DATA(iseq)->mark_bits.list = mark_offset_bits;
ISEQ_COMPILE_DATA(iseq)->is_single_mark_bit = false;
}
Expand Down Expand Up @@ -2891,11 +2897,11 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor)
}
else if (diff < 0) {
int label_no = adjust->label ? adjust->label->label_no : -1;
xfree(generated_iseq);
xfree(insns_info);
xfree(positions);
SIZED_FREE_N(generated_iseq, generated_iseq_size);
SIZED_FREE_N(insns_info, insns_info_size);
SIZED_FREE_N(positions, positions_size);
if (ISEQ_MBITS_BUFLEN(code_size) > 1) {
xfree(mark_offset_bits);
SIZED_FREE_N(mark_offset_bits, ISEQ_MBITS_BUFLEN(code_index));
}
debug_list(anchor, list);
COMPILE_ERROR(iseq, adjust->line_no,
Expand Down Expand Up @@ -2927,17 +2933,17 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor)
else {
body->mark_bits.list = NULL;
ISEQ_COMPILE_DATA(iseq)->mark_bits.list = NULL;
ruby_xfree(mark_offset_bits);
SIZED_FREE_N(mark_offset_bits, mark_offset_bits_size);
}
}

/* get rid of memory leak when REALLOC failed */
body->insns_info.body = insns_info;
body->insns_info.positions = positions;

REALLOC_N(insns_info, struct iseq_insn_info_entry, insns_info_index);
SIZED_REALLOC_N(insns_info, struct iseq_insn_info_entry, insns_info_index, insns_info_size);
body->insns_info.body = insns_info;
REALLOC_N(positions, unsigned int, insns_info_index);
SIZED_REALLOC_N(positions, unsigned int, insns_info_index, positions_size);
body->insns_info.positions = positions;
body->insns_info.size = insns_info_index;

Expand Down Expand Up @@ -13127,7 +13133,7 @@ ibf_load_code(const struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t bytecod
}
else {
load_body->mark_bits.list = 0;
ruby_xfree(mark_offset_bits);
SIZED_FREE_N(mark_offset_bits, ISEQ_MBITS_BUFLEN(iseq_size));
}
}

Expand Down Expand Up @@ -13312,7 +13318,7 @@ ibf_load_local_table(const struct ibf_load *load, ibf_offset_t local_table_offse
}

if (size == 1 && table[0] == idERROR_INFO) {
xfree(table);
ruby_sized_xfree(table, sizeof(ID) * size);
return rb_iseq_shared_exc_local_tbl;
}
else {
Expand Down Expand Up @@ -13616,7 +13622,7 @@ ibf_dump_iseq_each(struct ibf_dump *dump, const rb_iseq_t *iseq)

positions = rb_iseq_insns_info_decode_positions(ISEQ_BODY(iseq));
const ibf_offset_t insns_info_positions_offset = ibf_dump_insns_info_positions(dump, positions, body->insns_info.size);
ruby_xfree(positions);
SIZED_FREE_N(positions, ISEQ_BODY(iseq)->insns_info.size);

const ibf_offset_t local_table_offset = ibf_dump_local_table(dump, iseq);
const ibf_offset_t lvar_states_offset = ibf_dump_lvar_states(dump, iseq);
Expand Down Expand Up @@ -14944,7 +14950,7 @@ static void
ibf_loader_free(void *ptr)
{
struct ibf_load *load = (struct ibf_load *)ptr;
ruby_xfree(load);
SIZED_FREE(load);
}

static size_t
Expand Down
2 changes: 1 addition & 1 deletion concurrent_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static void
concurrent_set_free(void *ptr)
{
struct concurrent_set *set = ptr;
xfree(set->entries);
SIZED_FREE_N(set->entries, set->capacity);
}

static size_t
Expand Down
9 changes: 8 additions & 1 deletion cont.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ typedef struct rb_context_struct {
enum context_type type;
int argc;
int kw_splat;
bool root;
VALUE self;
VALUE value;

Expand Down Expand Up @@ -1102,7 +1103,12 @@ cont_free(void *ptr)
VM_ASSERT(cont->jit_cont != NULL);
jit_cont_free(cont->jit_cont);
/* free rb_cont_t or rb_fiber_t */
ruby_xfree(ptr);
if (cont->root) {
ruby_mimfree(ptr);
}
else {
ruby_xfree(ptr);
}
RUBY_FREE_LEAVE("cont");
}

Expand Down Expand Up @@ -2574,6 +2580,7 @@ rb_threadptr_root_fiber_setup(rb_thread_t *th)
}

fiber->cont.type = FIBER_CONTEXT;
fiber->cont.root = true;
fiber->cont.saved_ec.fiber_ptr = fiber;
fiber->cont.saved_ec.serial = next_ec_serial(th->ractor);
fiber->cont.saved_ec.thread_ptr = th;
Expand Down
14 changes: 7 additions & 7 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,7 @@ rb_gc_obj_free(void *objspace, VALUE obj)
st_free_table(ROBJECT_FIELDS_HASH(obj));
}
else {
xfree(ROBJECT(obj)->as.heap.fields);
SIZED_FREE_N(ROBJECT(obj)->as.heap.fields, ROBJECT_FIELDS_CAPACITY(obj));
RB_DEBUG_COUNTER_INC(obj_obj_ptr);
}
}
Expand Down Expand Up @@ -1550,7 +1550,7 @@ rb_gc_obj_free(void *objspace, VALUE obj)
}
#endif
onig_region_free(&rm->regs, 0);
xfree(rm->char_offset);
SIZED_FREE_N(rm->char_offset, rm->char_offset_num_allocated);

RB_DEBUG_COUNTER_INC(obj_match_ptr);
}
Expand Down Expand Up @@ -1587,7 +1587,7 @@ rb_gc_obj_free(void *objspace, VALUE obj)

case T_BIGNUM:
if (!BIGNUM_EMBED_P(obj) && BIGNUM_DIGITS(obj)) {
xfree(BIGNUM_DIGITS(obj));
SIZED_FREE_N(BIGNUM_DIGITS(obj), BIGNUM_LEN(obj));
RB_DEBUG_COUNTER_INC(obj_bignum_ptr);
}
else {
Expand All @@ -1605,7 +1605,7 @@ rb_gc_obj_free(void *objspace, VALUE obj)
RB_DEBUG_COUNTER_INC(obj_struct_embed);
}
else {
xfree((void *)RSTRUCT(obj)->as.heap.ptr);
SIZED_FREE_N(RSTRUCT(obj)->as.heap.ptr, RSTRUCT(obj)->as.heap.len);
RB_DEBUG_COUNTER_INC(obj_struct_ptr);
}
break;
Expand Down Expand Up @@ -3657,15 +3657,15 @@ rb_gc_unregister_address(VALUE *addr)

if (tmp->varptr == addr) {
vm->global_object_list = tmp->next;
xfree(tmp);
SIZED_FREE(tmp);
return;
}
while (tmp->next) {
if (tmp->next->varptr == addr) {
struct global_object_list *t = tmp->next;

tmp->next = tmp->next->next;
xfree(t);
SIZED_FREE(t);
break;
}
tmp = tmp->next;
Expand Down Expand Up @@ -3780,8 +3780,8 @@ gc_ref_update_object(void *objspace, VALUE v)
if (slot_size >= embed_size) {
// Object can be re-embedded
memcpy(ROBJECT(v)->as.ary, ptr, sizeof(VALUE) * ROBJECT_FIELDS_COUNT(v));
SIZED_FREE_N(ptr, ROBJECT_FIELDS_CAPACITY(v));
FL_UNSET_RAW(v, ROBJECT_HEAP);
xfree(ptr);
ptr = ROBJECT(v)->as.ary;
}
}
Expand Down
4 changes: 4 additions & 0 deletions gc/default/default.c
Original file line number Diff line number Diff line change
Expand Up @@ -8279,6 +8279,10 @@ rb_gc_impl_free(void *objspace_ptr, void *ptr, size_t old_size)
#if CALC_EXACT_MALLOC_SIZE
struct malloc_obj_info *info = (struct malloc_obj_info *)ptr - 1;
#if VERIFY_FREE_SIZE
if (!info->size) {
rb_bug("buffer %p has no recorded size. Was it allocated with ruby_mimalloc? If so it should be freed with ruby_mimfree", ptr);
}

if (old_size && (old_size + sizeof(struct malloc_obj_info)) != info->size) {
rb_bug("buffer %p freed with old_size=%lu, but was allocated with size=%lu", ptr, old_size, info->size - sizeof(struct malloc_obj_info));
}
Expand Down
4 changes: 2 additions & 2 deletions gems/bundled_gems
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ net-pop 0.1.2 https://github.com/ruby/net-pop
net-smtp 0.5.1 https://github.com/ruby/net-smtp
matrix 0.4.3 https://github.com/ruby/matrix
prime 0.1.4 https://github.com/ruby/prime
rbs 3.10.2 https://github.com/ruby/rbs
rbs 3.10.3 https://github.com/ruby/rbs
typeprof 0.31.1 https://github.com/ruby/typeprof
debug 1.11.1 https://github.com/ruby/debug
racc 1.8.1 https://github.com/ruby/racc
Expand All @@ -34,7 +34,7 @@ drb 2.2.3 https://github.com/ruby/drb
nkf 0.2.0 https://github.com/ruby/nkf
syslog 0.4.0 https://github.com/ruby/syslog
csv 3.3.5 https://github.com/ruby/csv
repl_type_completor 0.1.12 https://github.com/ruby/repl_type_completor 26b8e964557690c0b539cff8940bcfb1591f1fe6
repl_type_completor 0.1.13 https://github.com/ruby/repl_type_completor
ostruct 0.6.3 https://github.com/ruby/ostruct
pstore 0.2.0 https://github.com/ruby/pstore
benchmark 0.5.0 https://github.com/ruby/benchmark
Expand Down
3 changes: 3 additions & 0 deletions internal/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ ruby_sized_xfree_inlined(void *ptr, size_t size)
# define SIZED_REALLOC_N(v, T, m, n) \
((v) = (T *)ruby_sized_xrealloc2((void *)(v), (m), sizeof(T), (n)))

# define SIZED_FREE(v) ruby_sized_xfree((void *)(v), sizeof(*(v)))
# define SIZED_FREE_N(v, n) ruby_sized_xfree((void *)(v), sizeof(*(v)) * n)

static inline void *
ruby_sized_realloc_n(void *ptr, size_t new_count, size_t element_size, size_t old_count)
{
Expand Down
2 changes: 1 addition & 1 deletion jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ rb_jit_get_proc_ptr(VALUE procv)
}

VALUE
rb_optimized_call(VALUE *recv, rb_execution_context_t *ec, int argc, VALUE *argv, int kw_splat, VALUE block_handler)
rb_optimized_call(VALUE recv, rb_execution_context_t *ec, int argc, VALUE *argv, int kw_splat, VALUE block_handler)
{
rb_proc_t *proc;
GetProcPtr(recv, proc);
Expand Down
Loading