Fix memory corruption on Python 3.