From 0240572c44c64c3ab1d498d32a9a1530ab91b0da Mon Sep 17 00:00:00 2001 From: Roger Meier Date: Sun, 12 Jan 2014 23:29:11 +0100 Subject: [PATCH] THRIFT-2182 rb: segfault in regression tests (GC bug in rb_thrift_memory_buffer_write) Patch: Paul Brannan --- lib/rb/ext/compact_protocol.c | 2 +- lib/rb/ext/memory_buffer.c | 2 +- lib/rb/ext/struct.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/rb/ext/compact_protocol.c b/lib/rb/ext/compact_protocol.c index 1637e995..725d3381 100644 --- a/lib/rb/ext/compact_protocol.c +++ b/lib/rb/ext/compact_protocol.c @@ -315,7 +315,7 @@ VALUE rb_thrift_compact_proto_write_binary(VALUE self, VALUE buf) { buf = force_binary_encoding(buf); VALUE transport = GET_TRANSPORT(self); write_varint32(transport, RSTRING_LEN(buf)); - WRITE(transport, RSTRING_PTR(buf), RSTRING_LEN(buf)); + WRITE(transport, StringValuePtr(buf), RSTRING_LEN(buf)); return Qnil; } diff --git a/lib/rb/ext/memory_buffer.c b/lib/rb/ext/memory_buffer.c index e7253dcf..8b52c4a3 100644 --- a/lib/rb/ext/memory_buffer.c +++ b/lib/rb/ext/memory_buffer.c @@ -39,7 +39,7 @@ VALUE rb_thrift_memory_buffer_read_into_buffer(VALUE self, VALUE buffer_value, V VALUE rb_thrift_memory_buffer_write(VALUE self, VALUE str) { VALUE buf = GET_BUF(self); str = force_binary_encoding(str); - rb_str_buf_cat(buf, RSTRING_PTR(str), RSTRING_LEN(str)); + rb_str_buf_cat(buf, StringValuePtr(str), RSTRING_LEN(str)); return Qnil; } diff --git a/lib/rb/ext/struct.c b/lib/rb/ext/struct.c index 8fbadbee..313da4c8 100644 --- a/lib/rb/ext/struct.c +++ b/lib/rb/ext/struct.c @@ -607,7 +607,7 @@ static VALUE rb_thrift_union_read(VALUE self, VALUE protocol) { if (field_type == specified_type) { // read the value VALUE name = rb_hash_aref(field_info, name_sym); - rb_iv_set(self, "@setfield", ID2SYM(rb_intern(RSTRING_PTR(name)))); + rb_iv_set(self, "@setfield", rb_str_intern(name)); rb_iv_set(self, "@value", read_anything(protocol, field_type, field_info)); } else { rb_funcall(protocol, skip_method_id, 1, field_type_value); -- 2.17.1