Skip to content

Free after insert in generic_ivar_set_shape_fields #13635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2025
Merged
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
29 changes: 20 additions & 9 deletions variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -1227,12 +1227,6 @@ gen_fields_tbl_bytes(size_t n)
return offsetof(struct gen_fields_tbl, as.shape.fields) + n * sizeof(VALUE);
}

static struct gen_fields_tbl *
gen_fields_tbl_resize(struct gen_fields_tbl *old, uint32_t new_capa)
{
RUBY_ASSERT(new_capa > 0);
return xrealloc(old, gen_fields_tbl_bytes(new_capa));
}

void
rb_mark_generic_ivar(VALUE obj)
Expand Down Expand Up @@ -1837,13 +1831,28 @@ generic_ivar_set_shape_fields(VALUE obj, void *data)
int existing = st_lookup(tbl, (st_data_t)obj, (st_data_t *)&fields_tbl);

if (!existing || fields_lookup->resize) {
uint32_t new_capa = RSHAPE_CAPACITY(fields_lookup->shape_id);
uint32_t old_capa = RSHAPE_CAPACITY(RSHAPE_PARENT(fields_lookup->shape_id));

if (existing) {
RUBY_ASSERT(RSHAPE_TYPE_P(fields_lookup->shape_id, SHAPE_IVAR) || RSHAPE_TYPE_P(fields_lookup->shape_id, SHAPE_OBJ_ID));
RUBY_ASSERT(RSHAPE_CAPACITY(RSHAPE_PARENT(fields_lookup->shape_id)) < RSHAPE_CAPACITY(fields_lookup->shape_id));
RUBY_ASSERT(old_capa < new_capa);
RUBY_ASSERT(fields_tbl);
} else {
RUBY_ASSERT(!fields_tbl);
RUBY_ASSERT(old_capa == 0);
}
RUBY_ASSERT(new_capa > 0);

fields_tbl = gen_fields_tbl_resize(fields_tbl, RSHAPE_CAPACITY(fields_lookup->shape_id));
struct gen_fields_tbl *old_fields_tbl = fields_tbl;
fields_tbl = xmalloc(gen_fields_tbl_bytes(new_capa));
if (old_fields_tbl) {
memcpy(fields_tbl, old_fields_tbl, gen_fields_tbl_bytes(old_capa));
}
st_insert(tbl, (st_data_t)obj, (st_data_t)fields_tbl);
if (old_fields_tbl) {
xfree(old_fields_tbl);
}
}

if (fields_lookup->shape_id) {
Expand Down Expand Up @@ -2371,7 +2380,9 @@ rb_copy_generic_ivar(VALUE dest, VALUE obj)
return;
}

new_fields_tbl = gen_fields_tbl_resize(0, RSHAPE_CAPACITY(dest_shape_id));
uint32_t dest_capa = RSHAPE_CAPACITY(dest_shape_id);
RUBY_ASSERT(dest_capa > 0);
new_fields_tbl = xmalloc(gen_fields_tbl_bytes(dest_capa));

VALUE *src_buf = obj_fields_tbl->as.shape.fields;
VALUE *dest_buf = new_fields_tbl->as.shape.fields;
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy