Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 11204 invoked from network); 2 Nov 2008 22:05:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Nov 2008 22:05:59 -0000 Received: (qmail 80673 invoked by uid 500); 2 Nov 2008 22:06:05 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 80655 invoked by uid 500); 2 Nov 2008 22:06:05 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 80646 invoked by uid 99); 2 Nov 2008 22:06:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 02 Nov 2008 14:06:05 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 02 Nov 2008 22:04:56 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2933E2388879; Sun, 2 Nov 2008 14:05:08 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081102220508.2933E2388879@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 +#include 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 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 #include #include "decaf/internal/nio/BufferFactory.h" +#include 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 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 chars( result, 0 ); + get( &chars[0], 0, result ); + target->put( &chars[0], 0, result ); return result; }