Fix memory management issues.