Protecting a diamond quantum memory by charge state control