diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h
index 822ccfb11..17b78da8e 100644
--- a/tests/core_tests/chaingen.h
+++ b/tests/core_tests/chaingen.h
@@ -498,7 +498,9 @@ inline bool do_replay_events(std::vector<test_event_entry>& events)
     return false;
   }
   t_test_class validator;
-  return replay_events_through_core<t_test_class>(c, events, validator);
+  bool ret = replay_events_through_core<t_test_class>(c, events, validator);
+  c.deinit();
+  return ret;
 }
 //--------------------------------------------------------------------------
 template<class t_test_class>