summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/stringio/stringio.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index 96e82ff5c1..99a19ead0d 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -698,15 +698,19 @@ strio_eof(VALUE self)
static VALUE
strio_copy(VALUE copy, VALUE orig)
{
- struct StringIO *ptr;
+ struct StringIO *ptr, *old_ptr;
+ VALUE old_string = Qundef;
orig = rb_convert_type(orig, T_DATA, "StringIO", "to_strio");
if (copy == orig) return copy;
ptr = StringIO(orig);
- if (check_strio(copy)) {
- strio_free(DATA_PTR(copy));
+ old_ptr = check_strio(copy);
+ if (old_ptr) {
+ old_string = old_ptr->string;
+ strio_free(old_ptr);
}
DATA_PTR(copy) = ptr;
+ RB_OBJ_WRITTEN(copy, old_string, ptr->string);
RBASIC(copy)->flags &= ~STRIO_READWRITE;
RBASIC(copy)->flags |= RBASIC(orig)->flags & STRIO_READWRITE;
++ptr->count;