Skip to content

Commit

Permalink
Fix segfault in mrb_proc_copy.
Browse files Browse the repository at this point in the history
  • Loading branch information
clayton-shopify committed Dec 2, 2016
1 parent 2cca9d3 commit 1ff4b3f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ mrb_proc_copy(struct RProc *a, struct RProc *b)
{
a->flags = b->flags;
a->body = b->body;
if (!MRB_PROC_CFUNC_P(a)) {
if (!MRB_PROC_CFUNC_P(a) && a->body.irep) {
a->body.irep->refcnt++;
}
a->target_class = b->target_class;
Expand Down
16 changes: 16 additions & 0 deletions test/t/proc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,19 @@ def obj.to_proc

assert_raise(TypeError){ mock(&(Object.new)) }
end

assert('initialize_copy works when initialize is removed') do
begin
Proc.alias_method(:old_initialize, :initialize)
Proc.remove_method(:initialize)

a = Proc.new {}
b = Proc.new {}
assert_nothing_raised do
a.initialize_copy(b)
end
ensure
Proc.alias_method(:initialize, :old_initialize)
Proc.remove_method(:old_initialize)
end
end

0 comments on commit 1ff4b3f

Please sign in to comment.