Fix invalid memory access in python2.