Fixed memory leak in anomaly detection