Commit 55f7d4ba
55f7d4ba3081Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified
Description
Merge pull request #1177 from rubys/fix/poly-each-receiver-gc-root
Root the poly each-loop receiver temp across the loop body
Details
- Commit
- 55f7d4ba3081
- Parent
- b2a0379d21c4
- Merge parent
- 3e8f5d8ea459
spinel_codegen.rbmodifiedView file
@@ -42178,6 +42178,16 @@
4217842178
idx_tmp = new_temp4217942179
val_tmp = new_temp4218042180
emit(" sp_RbVal " + poly_tmp + " = " + rc + ";")42181+
# Root the receiver temp across the loop body. `rc` is frequently a42182+
# fresh method-call result (e.g. `@article.comments`) held only in42183+
# this temp; the loop body allocates (string append, nested render,42184+
# box helpers), so an unrooted PtrArray/heap collection here can be42185+
# collected mid-iteration, leaving sp_PtrArray_get to read a freed42186+
# slot (observed as a SIGSEGV in sp_obj_cls_id_of on a garbage42187+
# pointer under load). The cleanup-attributed root pops at end of42188+
# poly_tmp's C scope, which is exactly the loop's extent.42189+
@needs_gc = 142190+
emit_gc_root_for_expr(poly_tmp, "poly")4218142191
emit(" if (" + poly_tmp + ".tag == SP_TAG_OBJ) {")4218242192
emit(" mrb_int " + idx_tmp + "_len = 0;")4218342193
emit(" if (" + poly_tmp + ".cls_id == SP_BUILTIN_RANGE) " + idx_tmp + "_len = ((sp_Range *)" + poly_tmp + ".v.p)->last - ((sp_Range *)" + poly_tmp + ".v.p)->first + 1;")test/poly_each_receiver_gc_root.rbaddedView file
Loading diff…
test/poly_each_receiver_gc_root.rb.expectedaddedView file
Loading diff…