summaryrefslogtreecommitdiff
path: root/marshal.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-16 03:45:15 (GMT)
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-16 03:45:15 (GMT)
commitf97051512aad857eed0b3ed8676c4c123f6a01c4 (patch)
tree3aac5f209f9855b2f386dcc913cbe261512addb4 /marshal.c
parent401cf928c104bcba494b2c30daf3a6c48c744c12 (diff)
marshal.c: use rb_gc_force_recycle for GC-safety
Putting rb_gc_force_recycle at the end of the function has a nice side-effect of keeping wrapper visible to GC until the moment of recycle, preventing GC from prematurely killing live objects. volatile is a common source of compiler bugs/differences, avoid it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'marshal.c')
-rw-r--r--marshal.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/marshal.c b/marshal.c
index e469b4e..b8106d7 100644
--- a/marshal.c
+++ b/marshal.c
@@ -950,7 +950,7 @@ marshal_dump(int argc, VALUE *argv)
VALUE obj, port, a1, a2;
int limit = -1;
struct dump_arg *arg;
- volatile VALUE wrapper;
+ VALUE wrapper; /* used to avoid memory leak in case of exception */
port = Qnil;
rb_scan_args(argc, argv, "12", &obj, &a1, &a2);
@@ -964,7 +964,7 @@ marshal_dump(int argc, VALUE *argv)
else if (NIL_P(a1)) io_needed();
else port = a1;
}
- RB_GC_GUARD(wrapper) = TypedData_Make_Struct(rb_cData, struct dump_arg, &dump_arg_data, arg);
+ wrapper = TypedData_Make_Struct(rb_cData, struct dump_arg, &dump_arg_data, arg);
arg->dest = 0;
arg->symbols = st_init_numtable();
arg->data = st_init_numtable();
@@ -993,8 +993,8 @@ marshal_dump(int argc, VALUE *argv)
rb_io_write(arg->dest, arg->str);
rb_str_resize(arg->str, 0);
}
- clear_dump_arg(arg);
- RB_GC_GUARD(wrapper);
+ free_dump_arg(arg);
+ rb_gc_force_recycle(wrapper); /* also guards from premature GC */
return port;
}
@@ -1957,7 +1957,7 @@ marshal_load(int argc, VALUE *argv)
VALUE port, proc;
int major, minor, infection = 0;
VALUE v;
- volatile VALUE wrapper;
+ VALUE wrapper; /* used to avoid memory leak in case of exception */
struct load_arg *arg;
rb_scan_args(argc, argv, "11", &port, &proc);
@@ -1973,7 +1973,7 @@ marshal_load(int argc, VALUE *argv)
else {
io_needed();
}
- RB_GC_GUARD(wrapper) = TypedData_Make_Struct(rb_cData, struct load_arg, &load_arg_data, arg);
+ wrapper = TypedData_Make_Struct(rb_cData, struct load_arg, &load_arg_data, arg);
arg->infection = infection;
arg->src = port;
arg->offset = 0;
@@ -2004,8 +2004,8 @@ marshal_load(int argc, VALUE *argv)
if (!NIL_P(proc)) arg->proc = proc;
v = r_object(arg);
- clear_load_arg(arg);
- RB_GC_GUARD(wrapper);
+ free_load_arg(arg);
+ rb_gc_force_recycle(wrapper); /* also guards from premature GC */
return v;
}