Index: /trunk/FACT++/src/StateMachineImp.cc
===================================================================
--- /trunk/FACT++/src/StateMachineImp.cc	(revision 16088)
+++ /trunk/FACT++/src/StateMachineImp.cc	(revision 16089)
@@ -137,16 +137,4 @@
     for (vector<EventImp*>::iterator cmd=fListOfEvents.begin(); cmd!=fListOfEvents.end(); cmd++)
         delete *cmd;
-
-    // Unfortunately, front() doesn't necessarily return 0 if
-    // queue is empty
-    while (fEventQueue.size())
-    {
-        Event *q=fEventQueue.front();
-        if (!q)
-            break;
-
-        fEventQueue.pop();
-        delete q;
-    }
 }
 
@@ -178,5 +166,5 @@
 {
     const lock_guard<mutex> guard(fMutex);
-    fEventQueue.push(cmd);
+    fEventQueue.push_back(shared_ptr<Event>(cmd));
 }
 
@@ -190,5 +178,5 @@
 //!    A pointer to an Event object
 //
-Event *StateMachineImp::PopEvent()
+shared_ptr<Event> StateMachineImp::PopEvent()
 {
     const lock_guard<mutex> guard(fMutex);
@@ -196,7 +184,6 @@
     // Get the next event from the stack
     // and remove event from the stack
-    Event *cmd = fEventQueue.front();
-    fEventQueue.pop();
-
+    const shared_ptr<Event> cmd = fEventQueue.front();
+    fEventQueue.pop_front();
     return cmd;
 }
@@ -1037,5 +1024,5 @@
 
             // Pop the next command which arrived from the stack
-            const auto_ptr<Event> cmd(PopEvent());
+            const shared_ptr<Event> cmd(PopEvent());
 
             if (!HandleEvent(*cmd))
Index: /trunk/FACT++/src/StateMachineImp.h
===================================================================
--- /trunk/FACT++/src/StateMachineImp.h	(revision 16088)
+++ /trunk/FACT++/src/StateMachineImp.h	(revision 16089)
@@ -3,7 +3,8 @@
 
 #include <map>
-#include <queue>
+#include <list>
 #include <mutex>
 #include <vector>
+#include <memory>
 
 #include "MainImp.h"
@@ -43,5 +44,5 @@
 private:
     std::vector<EventImp*> fListOfEvents; /// List of available commands as setup by user
-    std::queue<Event*>     fEventQueue;   /// Event queue (fifo) for the received commands
+    std::list<std::shared_ptr<Event>> fEventQueue;   /// Event queue (fifo) for the received commands
 
     std::mutex fMutex;    /// Mutex to ensure thread-safe access to the command fifo
@@ -54,6 +55,6 @@
     /// Push a command into the fifo. The fifo takes over ownership
     void PushEvent(Event *cmd);
-    /// Pop a command from the fifo. You take over owenership
-    Event *PopEvent();
+    /// Pop a command from the fifo.
+    std::shared_ptr<Event> PopEvent();
 
     bool HandleNewState(int newstate, const EventImp *evt, const char *txt);
@@ -137,5 +138,5 @@
     EventImp *FindEvent(const std::string &evt);
 
-    bool IsQueueEmpty() const { return fEventQueue.size()==0; }
+    bool IsQueueEmpty() const { return fEventQueue.empty(); }
 
     //const std::vector<EventImp*> &GetListOfEvents() const { return fListOfEvents; }
