activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r709950 - in /activemq/activemq-cpp/trunk/src/main/decaf: internal/nio/CharArrayBuffer.cpp nio/CharBuffer.cpp
Date Sun, 02 Nov 2008 22:05:07 GMT
Author: tabish
Date: Sun Nov  2 14:05:07 2008
New Revision: 709950

URL: http://svn.apache.org/viewvc?rev=709950&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQCPP-200

Fix possible memory leak

Modified:
    activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/CharArrayBuffer.cpp
    activemq/activemq-cpp/trunk/src/main/decaf/nio/CharBuffer.cpp

Modified: activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/CharArrayBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/CharArrayBuffer.cpp?rev=709950&r1=709949&r2=709950&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/CharArrayBuffer.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/CharArrayBuffer.cpp Sun Nov  2
14:05:07 2008
@@ -17,6 +17,7 @@
 
 #include "CharArrayBuffer.h"
 #include <string.h>
+#include <memory>
 
 using namespace decaf;
 using namespace decaf::lang;
@@ -305,6 +306,8 @@
 CharSequence* CharArrayBuffer::subSequence( std::size_t start, std::size_t end ) const
     throw ( decaf::lang::exceptions::IndexOutOfBoundsException ) {
 
+    CharArrayBuffer* buffer = NULL;
+
     try{
 
         if( start > end ) {
@@ -319,12 +322,11 @@
                 "CharArrayBuffer::subSequence - Sequence exceed limit" );
         }
 
-        CharArrayBuffer* buffer = new CharArrayBuffer( *this );
-
+        std::auto_ptr<CharArrayBuffer> buffer( new CharArrayBuffer( *this ) );
         buffer->position( this->position() + start );
         buffer->limit( this->position() + end );
 
-        return buffer;
+        return buffer.release();
     }
     DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )

Modified: activemq/activemq-cpp/trunk/src/main/decaf/nio/CharBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/nio/CharBuffer.cpp?rev=709950&r1=709949&r2=709950&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/nio/CharBuffer.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/nio/CharBuffer.cpp Sun Nov  2 14:05:07 2008
@@ -19,6 +19,7 @@
 #include <decaf/lang/Character.h>
 #include <decaf/lang/Math.h>
 #include "decaf/internal/nio/BufferFactory.h"
+#include <memory>
 
 using namespace std;
 using namespace decaf;
@@ -135,9 +136,8 @@
     try{
 
         if( value != NULL ) {
-            CharSequence* temp = value->subSequence( start, end );
-            this->append( temp );
-            delete temp;
+            auto_ptr<CharSequence> temp( value->subSequence( start, end ) );
+            this->append( temp.get() );
 
             return *this;
         }
@@ -391,10 +391,9 @@
         std::size_t result = (std::size_t)Math::min(
                 (int)target->remaining(),
                 (int)this->remaining() );
-        char* chars = new char[result];
-        get( chars, 0, result );
-        target->put( chars, 0, result );
-        delete [] chars;
+        std::vector<char> chars( result, 0 );
+        get( &chars[0], 0, result );
+        target->put( &chars[0], 0, result );
 
         return result;
     }



Mime
View raw message