Fixed a race condition!
[invirt/third/libt4.git] / rsm.cc
diff --git a/rsm.cc b/rsm.cc
index 54713cb..a44c24b 100644 (file)
--- a/rsm.cc
+++ b/rsm.cc
@@ -90,7 +90,7 @@ rsm::rsm(const string & _first, const string & _me) :
     stf(0), primary(_first), insync (false), inviewchange (true), vid_commit(0),
     partitioned (false), dopartition(false), break1(false), break2(false)
 {
-    cfg = new config(_first, _me, this);
+    cfg = unique_ptr<config>(new config(_first, _me, this));
 
     if (_first == _me) {
         // Commit the first view here. We can not have acceptor::acceptor
@@ -106,14 +106,16 @@ rsm::rsm(const string & _first, const string & _me) :
     rsmrpc->reg(rsm_protocol::joinreq, &rsm::joinreq, this);
 
     // tester must be on different port, otherwise it may partition itself
-    testsvr = new rpcs((in_port_t)stoi(_me) + 1);
+    testsvr = unique_ptr<rpcs>(new rpcs((in_port_t)stoi(_me) + 1));
     testsvr->reg(rsm_test_protocol::net_repair, &rsm::test_net_repairreq, this);
     testsvr->reg(rsm_test_protocol::breakpoint, &rsm::breakpointreq, this);
+}
 
-    {
-        lock ml(rsm_mutex);
-        thread(&rsm::recovery, this).detach();
-    }
+void rsm::start() {
+    lock ml(rsm_mutex);
+    rsmrpc->start();
+    testsvr->start();
+    thread(&rsm::recovery, this).detach();
 }
 
 void rsm::reg1(int proc, handler *h) {