Fix a refcount GMP callback issue, and add test for it