Skip to content

Commit 9519d16

Browse files
committed
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.
1 parent f430fbb commit 9519d16

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

io_buffer.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,7 +2569,9 @@ rb_io_buffer_initialize_copy(VALUE self, VALUE source)
25692569

25702570
io_buffer_initialize(self, buffer, NULL, source_size, io_flags_for_size(source_size), Qnil);
25712571

2572-
return io_buffer_copy_from(buffer, source_base, source_size, 0, NULL);
2572+
VALUE result = io_buffer_copy_from(buffer, source_base, source_size, 0, NULL);
2573+
RB_GC_GUARD(source);
2574+
return result;
25732575
}
25742576

25752577
/*
@@ -2654,7 +2656,9 @@ io_buffer_copy(int argc, VALUE *argv, VALUE self)
26542656

26552657
rb_io_buffer_get_bytes_for_reading(source, &source_base, &source_size);
26562658

2657-
return io_buffer_copy_from(buffer, source_base, source_size, argc-1, argv+1);
2659+
VALUE result = io_buffer_copy_from(buffer, source_base, source_size, argc-1, argv+1);
2660+
RB_GC_GUARD(source);
2661+
return result;
26582662
}
26592663

26602664
/*
@@ -2732,7 +2736,9 @@ io_buffer_set_string(int argc, VALUE *argv, VALUE self)
27322736
const void *source_base = RSTRING_PTR(string);
27332737
size_t source_size = RSTRING_LEN(string);
27342738

2735-
return io_buffer_copy_from(buffer, source_base, source_size, argc-1, argv+1);
2739+
VALUE result = io_buffer_copy_from(buffer, source_base, source_size, argc-1, argv+1);
2740+
RB_GC_GUARD(string);
2741+
return result;
27362742
}
27372743

27382744
void

0 commit comments

Comments
 (0)