Fix possible memory leak in Python 2 branch