Copy rbc state more precisely and fix memory management bug.