From 45b5d1cc1f48ed8f6caef8ee9652f788d69747a5 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Fri, 19 Mar 2010 17:04:18 +0000 Subject: QPID-664: Prevent dangling pointers when receiver/sender handles stay in scope after connection/session handles goes out of scope. This change require connections to be closed explicitly to avoid leaking memory. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@925332 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/tests/qpid_recv.cpp | 3 ++- cpp/src/tests/qpid_send.cpp | 3 ++- cpp/src/tests/qpid_stream.cpp | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'cpp/src/tests') diff --git a/cpp/src/tests/qpid_recv.cpp b/cpp/src/tests/qpid_recv.cpp index e4cc6a7ac8..10738578ed 100644 --- a/cpp/src/tests/qpid_recv.cpp +++ b/cpp/src/tests/qpid_recv.cpp @@ -148,8 +148,8 @@ int main(int argc, char ** argv) { Options opts; if (opts.parse(argc, argv)) { + Connection connection(opts.connectionOptions); try { - Connection connection(opts.connectionOptions); connection.open(opts.url); std::auto_ptr updates(opts.failoverUpdates ? new FailoverUpdates(connection) : 0); Session session = connection.newSession(opts.tx > 0); @@ -207,6 +207,7 @@ int main(int argc, char ** argv) return 0; } catch(const std::exception& error) { std::cerr << "Failure: " << error.what() << std::endl; + connection.close(); } } return 1; diff --git a/cpp/src/tests/qpid_send.cpp b/cpp/src/tests/qpid_send.cpp index 50e6c4371a..a8b0241a1d 100644 --- a/cpp/src/tests/qpid_send.cpp +++ b/cpp/src/tests/qpid_send.cpp @@ -181,8 +181,8 @@ int main(int argc, char ** argv) { Options opts; if (opts.parse(argc, argv)) { + Connection connection(opts.connectionOptions); try { - Connection connection(opts.connectionOptions); connection.open(opts.url); std::auto_ptr updates(opts.failoverUpdates ? new FailoverUpdates(connection) : 0); Session session = connection.newSession(opts.tx > 0); @@ -230,6 +230,7 @@ int main(int argc, char ** argv) return 0; } catch(const std::exception& error) { std::cout << "Failed: " << error.what() << std::endl; + connection.close(); } } return 1; diff --git a/cpp/src/tests/qpid_stream.cpp b/cpp/src/tests/qpid_stream.cpp index ef0aea52e4..5ed7f84492 100644 --- a/cpp/src/tests/qpid_stream.cpp +++ b/cpp/src/tests/qpid_stream.cpp @@ -87,8 +87,8 @@ struct Client : qpid::sys::Runnable void run() { + Connection connection; try { - Connection connection; connection.open(opts.url); Session session = connection.newSession(); doWork(session); @@ -96,6 +96,7 @@ struct Client : qpid::sys::Runnable connection.close(); } catch(const std::exception& error) { std::cout << error.what() << std::endl; + connection.close(); } } -- cgit v1.2.1