The fix is to modify `bint_set` to ensure that the data stored in the persistent `RBigint` object is allocated on the heap if it's not embedded. We check if the source `mpz_t` uses memory from the stack pool using `is_pool_memory`. If it does, we must perform a deep copy (`mpz_set`) to allocate new heap memory and copy the data, instead of moving the pointer (`mpz_move`). If the source is already on the heap, we retain the efficient `mpz_move`. OSS-Fuzz testcase: https://oss-fuzz.com/testcase-detail/5279371075321856
matz added a commit that referenced this pull request
Oct 27, 2025refactored the stack-use-after-return fix to encapsulate pool memory handling in mpz_move instead of bint_set, providing cleaner code and automatic protection for all 22 callers of mpz_move; ref #6651 Co-authored-by: Claude <noreply@anthropic.com>