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_temp
4217942179 val_tmp = new_temp
4218042180 emit(" sp_RbVal " + poly_tmp + " = " + rc + ";")
42181+ # Root the receiver temp across the loop body. `rc` is frequently a
42182+ # fresh method-call result (e.g. `@article.comments`) held only in
42183+ # this temp; the loop body allocates (string append, nested render,
42184+ # box helpers), so an unrooted PtrArray/heap collection here can be
42185+ # collected mid-iteration, leaving sp_PtrArray_get to read a freed
42186+ # slot (observed as a SIGSEGV in sp_obj_cls_id_of on a garbage
42187+ # pointer under load). The cleanup-attributed root pops at end of
42188+ # poly_tmp's C scope, which is exactly the loop's extent.
42189+ @needs_gc = 1
42190+ 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;")