Skip to content
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

Fix memory leak in util_spec_rb_get_kwargs #1134

Merged
merged 1 commit into from
Feb 6, 2024
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
17 changes: 6 additions & 11 deletions optional/capi/ext/util_spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,17 @@ static VALUE util_spec_rb_get_kwargs(VALUE self, VALUE keyword_hash, VALUE keys,
int len = RARRAY_LENINT(keys);

int values_len = req + (opt < 0 ? -1 - opt : opt);
int i = 0;

ID *ids = (ID*) malloc(sizeof(VALUE) * len);
VALUE *results = (VALUE*) malloc(sizeof(VALUE) * values_len);
int extracted = 0;
VALUE ary = Qundef;
ID *ids = (ID *)alloca(sizeof(VALUE) * len);
VALUE *results = (VALUE *)alloca(sizeof(VALUE) * values_len);

for (i = 0; i < len; i++) {
for (int i = 0; i < len; i++) {
ids[i] = SYM2ID(rb_ary_entry(keys, i));
}

extracted = rb_get_kwargs(keyword_hash, ids, req, opt, results);
ary = rb_ary_new_from_values(extracted, results);
free(results);
free(ids);
return ary;
int extracted = rb_get_kwargs(keyword_hash, ids, req, opt, results);

return rb_ary_new_from_values(extracted, results);
}

static VALUE util_spec_rb_long2int(VALUE self, VALUE n) {
Expand Down