Fixed memory leaks in rms error calculation.