IO::Buffer: Guard arguments from GC

At least, `string` in `io_buffer_set_string` can be different from
`argv[0]` after `rb_str_to_str` call.  The other cases may not be
necessary.
This commit is contained in:
Nobuyoshi Nakada 2025-11-22 23:41:23 +09:00 committed by Nobuyoshi Nakada
parent f430fbbfac
commit 9519d16381
Notes: git 2025-12-17 03:36:13 +00:00

View File

@ -2569,7 +2569,9 @@ rb_io_buffer_initialize_copy(VALUE self, VALUE source)
io_buffer_initialize(self, buffer, NULL, source_size, io_flags_for_size(source_size), Qnil);
return io_buffer_copy_from(buffer, source_base, source_size, 0, NULL);
VALUE result = io_buffer_copy_from(buffer, source_base, source_size, 0, NULL);
RB_GC_GUARD(source);
return result;
}
/*
@ -2654,7 +2656,9 @@ io_buffer_copy(int argc, VALUE *argv, VALUE self)
rb_io_buffer_get_bytes_for_reading(source, &source_base, &source_size);
return io_buffer_copy_from(buffer, source_base, source_size, argc-1, argv+1);
VALUE result = io_buffer_copy_from(buffer, source_base, source_size, argc-1, argv+1);
RB_GC_GUARD(source);
return result;
}
/*
@ -2732,7 +2736,9 @@ io_buffer_set_string(int argc, VALUE *argv, VALUE self)
const void *source_base = RSTRING_PTR(string);
size_t source_size = RSTRING_LEN(string);
return io_buffer_copy_from(buffer, source_base, source_size, argc-1, argv+1);
VALUE result = io_buffer_copy_from(buffer, source_base, source_size, argc-1, argv+1);
RB_GC_GUARD(string);
return result;
}
void