libt2n: (tomj) don't use std::auto_ptr in command_client, the pointer will get lost...
[libt2n] / src / command_client.cpp
index 52ca0f1..5d71692 100644 (file)
@@ -39,8 +39,15 @@ using namespace std;
 namespace libt2n
 {
 
+/**
+ * Constructor
+ * @param _c connection for this command. Ownership of the pointer is outside.
+ * @param _command_timeout_usec timeout until the command has to be completed
+ * @param _hello_timeout_usec timeout until hello has to be received
+ */
 command_client::command_client(client_connection* _c, long long _command_timeout_usec, long long _hello_timeout_usec)
     : c(_c)
+    , constructorException(NULL)
 {
     command_timeout_usec=_command_timeout_usec;
     hello_timeout_usec=_hello_timeout_usec;
@@ -60,8 +67,7 @@ command_client::command_client(client_connection* _c, long long _command_timeout
             c->close();
 
             // store a copy of the exception that you can find out details about the error later
-            std::auto_ptr<t2n_exception> tmp(e.clone());
-            constructorException=tmp;
+            constructorException = e.clone();
         }
         catch (...)
         {
@@ -70,6 +76,18 @@ command_client::command_client(client_connection* _c, long long _command_timeout
     }
 }
 
+/**
+ * Destructor
+ */
+command_client::~command_client()
+{
+    if (constructorException)
+    {
+        delete constructorException;
+        constructorException = NULL;
+    }
+}
+
 /** @brief replace the connection currently in use with a new one
     @param _c pointer to the new connection
 
@@ -259,7 +277,7 @@ void command_client::send_command(command* cmd, result_container &res)
         (*ostr) << "sending command, decoded data: " << std::endl;
         boost::archive::xml_oarchive xo(*ostr);
         xo << BOOST_SERIALIZATION_NVP(cc);
-    }
+   }
 
     c->write(ofs.str());