Fix a bug where we could free invalid memory during checkpoint.

References issue #961.