diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-12-03 11:54:22 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2016-12-03 11:54:22 +0900 |
| commit | e673fbb35a0c439bb4685cd0a6784f93a4856c07 (patch) | |
| tree | 929a0c00c4720e0670110cc9601bf2fcc2c7b442 | |
| parent | d7589b10ed0011c41f007fa9bfdba7c529fc6b71 (diff) | |
| parent | 1ff4b3f800d369510658b7926a1d6dc9327d0422 (diff) | |
| download | mruby-e673fbb35a0c439bb4685cd0a6784f93a4856c07.tar.gz mruby-e673fbb35a0c439bb4685cd0a6784f93a4856c07.zip | |
Merge pull request #3321 from clayton-shopify/fix-proc-crash-upstream
Fix segfault in mrb_proc_copy.
| -rw-r--r-- | src/proc.c | 2 | ||||
| -rw-r--r-- | test/t/proc.rb | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/proc.c b/src/proc.c index 4f770932b..470547094 100644 --- a/src/proc.c +++ b/src/proc.c @@ -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; diff --git a/test/t/proc.rb b/test/t/proc.rb index bc9821f7c..29530e8dd 100644 --- a/test/t/proc.rb +++ b/test/t/proc.rb @@ -163,3 +163,19 @@ assert('&obj call to_proc if defined') do 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 |
