Fix several memory issues for persistent programs.