diff --git a/mrbgems/mruby-bigint/core/bigint.c b/mrbgems/mruby-bigint/core/bigint.c index fc43499a2..e447e0cb0 100644 --- a/mrbgems/mruby-bigint/core/bigint.c +++ b/mrbgems/mruby-bigint/core/bigint.c @@ -309,6 +309,15 @@ mpz_clear(mpz_ctx_t *ctx, mpz_t *s) static void mpz_move(mpz_ctx_t *ctx, mpz_t *y, mpz_t *x) { +#if MRB_BIGINT_POOL_SIZE > 0 + if (MPZ_HAS_POOL(ctx) && is_pool_memory(x, MPZ_POOL(ctx))) { + /* Source is pool memory - use deep copy instead of pointer transfer */ + mpz_set(ctx, y, x); + mpz_clear(ctx, x); + return; + } +#endif + /* Normal move: transfer ownership */ mpz_clear(ctx, y); y->sn = x->sn; y->sz = x->sz; @@ -2767,19 +2776,8 @@ bint_set(mpz_ctx_t *ctx, struct RBigint *b, mpz_t *x) } else { RBIGINT_SET_HEAP(b); -#if MRB_BIGINT_POOL_SIZE > 0 - if (MPZ_HAS_POOL(ctx) && is_pool_memory(x, MPZ_POOL(ctx))) { - /* mpz_move() cannot be used because x is in the pool. */ - mpz_set(ctx, &b->as.heap, x); - mpz_clear(ctx, x); - } - else { -#endif - mpz_move(ctx, &b->as.heap, x); - } -#if MRB_BIGINT_POOL_SIZE > 0 + mpz_move(ctx, &b->as.heap, x); } -#endif } static struct RBigint*