RAII-ify restore_mem

Seems like `current_state_buffer` could stand the RAII treatment, too, but I figured I would start small(er).