mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
29b3405283
when mpz_mod_2exp() is called with z == x (in-place operation), the function was calling mpz_clear(ctx, z) which freed x's memory, then attempting to access x->p[i] - reading freed memory. this caused Barrett reduction to produce incorrect results in modular exponentiation. the fix checks if z == x and handles in-place modification by adjusting the size and masking directly, without clearing. this is similar to the memory leak fix for pool→heap transitions. Co-authored-by: Claude <noreply@anthropic.com>