From 2b6ac135fa7071290289741c9e35747bb9f1012f Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 1 Mar 2014 10:42:48 +0000 Subject: Make Protocol take control of the socket object passed in. We pass a std::auto_ptr to every Protocol subclass when we construct it, and it takes control of this object. This reduces the risk of: * accidentally reusing the same SocketStream for multiple Protocols (it happened to me in testbackupstore); * holding onto a reference to the SocketStream; * allowing a locally-scoped SocketStream to go out of scope and be released while still being referenced by a live Protocol. --- test/backupstorepatch/testbackupstorepatch.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'test/backupstorepatch') diff --git a/test/backupstorepatch/testbackupstorepatch.cpp b/test/backupstorepatch/testbackupstorepatch.cpp index 42594652..96b93308 100644 --- a/test/backupstorepatch/testbackupstorepatch.cpp +++ b/test/backupstorepatch/testbackupstorepatch.cpp @@ -345,12 +345,13 @@ int test(int argc, const char *argv[]) { // Open a connection to the server - SocketStreamTLS conn; - conn.Open(context, Socket::TypeINET, "localhost", + SocketStreamTLS *pConn = new SocketStreamTLS; + std::auto_ptr apConn(pConn); + pConn->Open(context, Socket::TypeINET, "localhost", BOX_PORT_BBSTORED_TEST); // Make a protocol - BackupProtocolClient protocol(conn); + BackupProtocolClient protocol(apConn); // Login { @@ -454,7 +455,6 @@ int test(int argc, const char *argv[]) // Finish the connection protocol.QueryFinished(); - conn.Close(); } // Fill in initial dependency information @@ -528,10 +528,11 @@ int test(int argc, const char *argv[]) } // Open a connection to the server (need to do this each time, otherwise housekeeping won't delete files) - SocketStreamTLS conn; - conn.Open(context, Socket::TypeINET, "localhost", + SocketStreamTLS *pConn = new SocketStreamTLS; + std::auto_ptr apConn(pConn); + pConn->Open(context, Socket::TypeINET, "localhost", BOX_PORT_BBSTORED_TEST); - BackupProtocolClient protocol(conn); + BackupProtocolClient protocol(apConn); { std::auto_ptr serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); @@ -583,7 +584,6 @@ int test(int argc, const char *argv[]) // Close the connection protocol.QueryFinished(); - conn.Close(); // Mark one of the elements as deleted if(test_file_remove_order[deleteIndex] == -1) -- cgit v1.2.3