You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2015/07/29 21:07:35 UTC

activemq-cpp git commit: fix a memory leak

Repository: activemq-cpp
Updated Branches:
  refs/heads/master 0c9771107 -> 961ee1790


fix a memory leak

Project: http://git-wip-us.apache.org/repos/asf/activemq-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-cpp/commit/961ee179
Tree: http://git-wip-us.apache.org/repos/asf/activemq-cpp/tree/961ee179
Diff: http://git-wip-us.apache.org/repos/asf/activemq-cpp/diff/961ee179

Branch: refs/heads/master
Commit: 961ee1790be5338e6038078b23dde436d9deb255
Parents: 0c97711
Author: Timothy Bish <ta...@gmail.com>
Authored: Wed Jul 29 14:21:44 2015 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Wed Jul 29 14:21:44 2015 -0400

----------------------------------------------------------------------
 activemq-cpp/src/main/decaf/net/URL.cpp | 12 ++++++++++++
 1 file changed, 12 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/961ee179/activemq-cpp/src/main/decaf/net/URL.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/net/URL.cpp b/activemq-cpp/src/main/decaf/net/URL.cpp
index b9237b7..aba8dd2 100644
--- a/activemq-cpp/src/main/decaf/net/URL.cpp
+++ b/activemq-cpp/src/main/decaf/net/URL.cpp
@@ -140,6 +140,10 @@ URL::URL(const String& protocol, const String& host, int port, const String& fil
 ////////////////////////////////////////////////////////////////////////////////
 void URL::initialize(const URL* context, const String& theSpec, URLStreamHandler* handler) {
 
+    // If we throw in this method the constructor does not complete, so we
+    // need to protect against a leak of the URLImpl and release at the end.
+    Pointer<URLImpl> finalizer(impl);
+
     if (handler != NULL) {
         impl->streamHandler.reset(handler);
     }
@@ -195,12 +199,18 @@ void URL::initialize(const URL* context, const String& theSpec, URLStreamHandler
         throw MalformedURLException(
             __FILE__, __LINE__, "port out of range: %d", impl->url.getPort());
     }
+
+    finalizer.release();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void URL::initialize(const String& protocol, const String& host, int port,
                      const String& file, URLStreamHandler* handler) {
 
+    // If we throw in this method the constructor does not complete, so we
+    // need to protect against a leak of the URLImpl and release at the end.
+    Pointer<URLImpl> finalizer(impl);
+
     if (port < -1) {
         throw MalformedURLException(__FILE__, __LINE__, "Port out of range: %d", port);
     }
@@ -246,6 +256,8 @@ void URL::initialize(const String& protocol, const String& host, int port,
     } else {
         impl->streamHandler.reset(handler);
     }
+
+    finalizer.release();
 }
 
 ////////////////////////////////////////////////////////////////////////////////