[Libreoffice-commits] core.git: embeddedobj/source extensions/source
Takeshi Abe
tabe at fixedpoint.jp
Wed Apr 2 00:15:45 PDT 2014
embeddedobj/source/msole/olecomponent.cxx | 37 +++++++++----------
extensions/source/plugin/base/xplugin.cxx | 9 ++--
extensions/source/plugin/unx/mediator.cxx | 13 +++---
extensions/source/propctrlr/formcomponenthandler.cxx | 4 +-
extensions/source/scanner/grid.cxx | 10 ++---
extensions/source/scanner/sane.cxx | 33 ++++++----------
extensions/source/scanner/sanedlg.cxx | 12 ++----
7 files changed, 53 insertions(+), 65 deletions(-)
New commits:
commit 8f7c677dbba29123c48778a1024a535f36bca183
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date: Wed Apr 2 16:08:04 2014 +0900
Avoid possible resource leaks by boost::scoped_array
Change-Id: Ibf92b3098c50388d8b6d27f4476e613a1f8918b5
diff --git a/embeddedobj/source/msole/olecomponent.cxx b/embeddedobj/source/msole/olecomponent.cxx
index 1ebeca4..eb248ec1 100644
--- a/embeddedobj/source/msole/olecomponent.cxx
+++ b/embeddedobj/source/msole/olecomponent.cxx
@@ -40,6 +40,7 @@
#include <advisesink.hxx>
#include <oleembobj.hxx>
#include <mtnotification.hxx>
+#include <boost/scoped_array.hpp>
using namespace ::com::sun::star;
using namespace ::comphelper;
@@ -286,7 +287,7 @@ sal_Bool OleComponentNative_Impl::ConvertDataForFlavor( const STGMEDIUM& aMedium
{
// first the GDI-metafile must be generated
- unsigned char* pBuf = NULL;
+ boost::scoped_array<unsigned char> pBuf;
sal_uInt32 nBufSize = 0;
OUString aFormat;
@@ -297,23 +298,23 @@ sal_Bool OleComponentNative_Impl::ConvertDataForFlavor( const STGMEDIUM& aMedium
if ( pMF )
{
nBufSize = GetMetaFileBitsEx( pMF->hMF, 0, NULL ) + 22;
- pBuf = new unsigned char[nBufSize];
+ pBuf.reset(new unsigned char[nBufSize]);
// TODO/LATER: the unit size must be calculated correctly
- *( (long* )pBuf ) = 0x9ac6cdd7L;
- *( (short* )( pBuf+6 )) = ( SHORT ) 0;
- *( (short* )( pBuf+8 )) = ( SHORT ) 0;
- *( (short* )( pBuf+10 )) = ( SHORT ) pMF->xExt;
- *( (short* )( pBuf+12 )) = ( SHORT ) pMF->yExt;
- *( (short* )( pBuf+14 )) = ( USHORT ) 2540;
+ *( (long* )pBuf.get() ) = 0x9ac6cdd7L;
+ *( (short* )( pBuf.get()+6 )) = ( SHORT ) 0;
+ *( (short* )( pBuf.get()+8 )) = ( SHORT ) 0;
+ *( (short* )( pBuf.get()+10 )) = ( SHORT ) pMF->xExt;
+ *( (short* )( pBuf.get()+12 )) = ( SHORT ) pMF->yExt;
+ *( (short* )( pBuf.get()+14 )) = ( USHORT ) 2540;
- if ( nBufSize && nBufSize == GetMetaFileBitsEx( pMF->hMF, nBufSize - 22, pBuf + 22 ) )
+ if ( nBufSize && nBufSize == GetMetaFileBitsEx( pMF->hMF, nBufSize - 22, pBuf.get() + 22 ) )
{
if ( aFlavor.MimeType.matchAsciiL( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"", 57 ) )
{
- aResult <<= uno::Sequence< sal_Int8 >( ( sal_Int8* )pBuf, nBufSize );
+ aResult <<= uno::Sequence< sal_Int8 >( ( sal_Int8* )pBuf.get(), nBufSize );
bAnyIsReady = sal_True;
}
}
@@ -325,12 +326,12 @@ sal_Bool OleComponentNative_Impl::ConvertDataForFlavor( const STGMEDIUM& aMedium
{
aFormat = "image/x-emf";
nBufSize = GetEnhMetaFileBits( aMedium.hEnhMetaFile, 0, NULL );
- pBuf = new unsigned char[nBufSize];
- if ( nBufSize && nBufSize == GetEnhMetaFileBits( aMedium.hEnhMetaFile, nBufSize, pBuf ) )
+ pBuf.reset(new unsigned char[nBufSize]);
+ if ( nBufSize && nBufSize == GetEnhMetaFileBits( aMedium.hEnhMetaFile, nBufSize, pBuf.get() ) )
{
if ( aFlavor.MimeType.matchAsciiL( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"", 57 ) )
{
- aResult <<= uno::Sequence< sal_Int8 >( ( sal_Int8* )pBuf, nBufSize );
+ aResult <<= uno::Sequence< sal_Int8 >( ( sal_Int8* )pBuf.get(), nBufSize );
bAnyIsReady = sal_True;
}
}
@@ -339,12 +340,12 @@ sal_Bool OleComponentNative_Impl::ConvertDataForFlavor( const STGMEDIUM& aMedium
{
aFormat = "image/x-MS-bmp";
nBufSize = GetBitmapBits( aMedium.hBitmap, 0, NULL );
- pBuf = new unsigned char[nBufSize];
- if ( nBufSize && nBufSize == sal::static_int_cast< ULONG >( GetBitmapBits( aMedium.hBitmap, nBufSize, pBuf ) ) )
+ pBuf.reset(new unsigned char[nBufSize]);
+ if ( nBufSize && nBufSize == sal::static_int_cast< ULONG >( GetBitmapBits( aMedium.hBitmap, nBufSize, pBuf.get() ) ) )
{
if ( aFlavor.MimeType.matchAsciiL( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"", 54 ) )
{
- aResult <<= uno::Sequence< sal_Int8 >( ( sal_Int8* )pBuf, nBufSize );
+ aResult <<= uno::Sequence< sal_Int8 >( ( sal_Int8* )pBuf.get(), nBufSize );
bAnyIsReady = sal_True;
}
}
@@ -357,12 +358,10 @@ sal_Bool OleComponentNative_Impl::ConvertDataForFlavor( const STGMEDIUM& aMedium
&& aFlavor.DataType == m_aSupportedGraphFormats[nInd].DataType
&& aFlavor.DataType == getCppuType( (const uno::Sequence< sal_Int8 >*) 0 ) )
{
- bAnyIsReady = ConvertBufferToFormat( ( void* )pBuf, nBufSize, aFormat, aResult );
+ bAnyIsReady = ConvertBufferToFormat( ( void* )pBuf.get(), nBufSize, aFormat, aResult );
break;
}
}
-
- delete[] pBuf;
}
return bAnyIsReady;
diff --git a/extensions/source/plugin/base/xplugin.cxx b/extensions/source/plugin/base/xplugin.cxx
index 658d1ff..f85f7bd 100644
--- a/extensions/source/plugin/base/xplugin.cxx
+++ b/extensions/source/plugin/base/xplugin.cxx
@@ -60,6 +60,8 @@
#include <stdio.h>
#endif
+#include <boost/scoped_array.hpp>
+
using namespace com::sun::star;
using namespace com::sun::star::io;
using namespace com::sun::star::beans;
@@ -1085,21 +1087,20 @@ void PluginInputStream::writeBytes( const Sequence<sal_Int8>& Buffer ) throw(std
{
nBytes = (nBytes > nPos - m_nWritePos) ? nPos - m_nWritePos : nBytes;
- char* pBuffer = new char[ nBytes ];
+ boost::scoped_array<char> pBuffer(new char[ nBytes ]);
m_aFileStream.Seek( m_nWritePos );
- nBytes = m_aFileStream.Read( pBuffer, nBytes );
+ nBytes = m_aFileStream.Read( pBuffer.get(), nBytes );
int32_t nBytesRead = 0;
try
{
nBytesRead = m_pPlugin->getPluginComm()->NPP_Write(
- m_pPlugin->getNPPInstance(), &m_aNPStream, m_nWritePos, nBytes, pBuffer );
+ m_pPlugin->getNPPInstance(), &m_aNPStream, m_nWritePos, nBytes, pBuffer.get() );
}
catch( ... )
{
nBytesRead = 0;
}
- delete [] pBuffer;
if( nBytesRead < 0 )
{
diff --git a/extensions/source/plugin/unx/mediator.cxx b/extensions/source/plugin/unx/mediator.cxx
index a4eea38..347f5e2 100644
--- a/extensions/source/plugin/unx/mediator.cxx
+++ b/extensions/source/plugin/unx/mediator.cxx
@@ -32,6 +32,7 @@
#include <plugin/unx/mediator.hxx>
#include <sal/log.hxx>
#include <vcl/svapp.hxx>
+#include <boost/scoped_array.hpp>
#define MEDIATOR_MAGIC 0xf7a8d2f4
@@ -93,15 +94,14 @@ sal_uLong Mediator::SendMessage( sal_uLong nBytes, const char* pBytes, sal_uLong
if( ! m_bValid )
return nMessageID;
- sal_uLong* pBuffer = new sal_uLong[ (nBytes/sizeof(sal_uLong)) + 4 ];
+ boost::scoped_array<sal_uLong> pBuffer(new sal_uLong[ (nBytes/sizeof(sal_uLong)) + 4 ]);
pBuffer[ 0 ] = nMessageID;
pBuffer[ 1 ] = nBytes;
pBuffer[ 2 ] = MEDIATOR_MAGIC;
memcpy( &pBuffer[3], pBytes, (size_t)nBytes );
ssize_t nToWrite = nBytes + 3*sizeof( sal_uLong );
- bool bSuccess = (nToWrite == write( m_nSocket, pBuffer, nToWrite ));
+ bool bSuccess = (nToWrite == write( m_nSocket, pBuffer.get(), nToWrite ));
SAL_WARN_IF(!bSuccess, "extensions.plugin", "short write");
- delete [] pBuffer;
return nMessageID;
}
@@ -206,15 +206,15 @@ void MediatorListener::run()
{
if( nHeader[ 0 ] == 0 && nHeader[ 1 ] == 0 )
return;
- char* pBuffer = new char[ nHeader[ 1 ] ];
- if( m_pMediator && (sal_uLong)read( m_pMediator->m_nSocket, pBuffer, nHeader[ 1 ] ) == nHeader[ 1 ] )
+ boost::scoped_array<char> pBuffer(new char[ nHeader[ 1 ] ]);
+ if( m_pMediator && (sal_uLong)read( m_pMediator->m_nSocket, pBuffer.get(), nHeader[ 1 ] ) == nHeader[ 1 ] )
{
::osl::MutexGuard aMyGuard( m_aMutex );
{
osl::MutexGuard
aGuard( m_pMediator->m_aQueueMutex );
MediatorMessage* pMessage =
- new MediatorMessage( nHeader[ 0 ], nHeader[ 1 ], pBuffer );
+ new MediatorMessage( nHeader[ 0 ], nHeader[ 1 ], pBuffer.get() );
m_pMediator->m_aMessageQueue.push_back( pMessage );
}
m_pMediator->m_aNewMessageCdtn.set();
@@ -228,7 +228,6 @@ void MediatorListener::run()
<< nHeader[1] << ", ... }");
bRun = false;
}
- delete [] pBuffer;
}
else
{
diff --git a/extensions/source/propctrlr/formcomponenthandler.cxx b/extensions/source/propctrlr/formcomponenthandler.cxx
index b6f5724..bc0f6e52 100644
--- a/extensions/source/propctrlr/formcomponenthandler.cxx
+++ b/extensions/source/propctrlr/formcomponenthandler.cxx
@@ -100,6 +100,7 @@
#include <sal/macros.h>
#include <limits>
+#include <boost/scoped_array.hpp>
#define GRAPHOBJ_URLPREFIX "vnd.sun.star.GraphicObject:"
@@ -381,7 +382,7 @@ namespace pcr
sal_Int32 nNewCount = aNewStrings.getLength();
// Create new Ids
- OUString* pNewPureIds = new OUString[nNewCount];
+ boost::scoped_array<OUString> pNewPureIds(new OUString[nNewCount]);
OUString aIdStrBase = aDot;
Any aNameAny = m_xComponent->getPropertyValue(PROPERTY_NAME);
OUString sControlName;
@@ -478,7 +479,6 @@ namespace pcr
{}
}
}
- delete[] pNewPureIds;
}
}
}
diff --git a/extensions/source/scanner/grid.cxx b/extensions/source/scanner/grid.cxx
index 5762bb5..8f12b06 100644
--- a/extensions/source/scanner/grid.cxx
+++ b/extensions/source/scanner/grid.cxx
@@ -29,6 +29,7 @@
// for ::std::sort
#include <algorithm>
+#include <boost/scoped_array.hpp>
ResId SaneResId( sal_uInt32 );
@@ -258,8 +259,8 @@ void GridWindow::computeNew()
int i;
// get node arrays
- double* nodex = new double[ nSorted ];
- double* nodey = new double[ nSorted ];
+ boost::scoped_array<double> nodex(new double[ nSorted ]);
+ boost::scoped_array<double> nodey(new double[ nSorted ]);
for( i = 0L; i < nSorted; i++ )
transform( m_aHandles[i].maPos, nodex[ i ], nodey[ i ] );
@@ -267,7 +268,7 @@ void GridWindow::computeNew()
for( i = 0; i < m_nValues; i++ )
{
double x = m_pXValues[ i ];
- m_pNewYValues[ i ] = interpolate( x, nodex, nodey, nSorted );
+ m_pNewYValues[ i ] = interpolate( x, nodex.get(), nodey.get(), nSorted );
if( m_bCutValues )
{
if( m_pNewYValues[ i ] > m_fMaxY )
@@ -276,9 +277,6 @@ void GridWindow::computeNew()
m_pNewYValues[ i ] = m_fMinY;
}
}
-
- delete [] nodex;
- delete [] nodey;
}
}
diff --git a/extensions/source/scanner/sane.cxx b/extensions/source/scanner/sane.cxx
index 96b7716..f89895c 100644
--- a/extensions/source/scanner/sane.cxx
+++ b/extensions/source/scanner/sane.cxx
@@ -29,6 +29,7 @@
#include <sys/types.h>
#include <sal/config.h>
#include <sal/macros.h>
+#include <boost/scoped_array.hpp>
#if (OSL_DEBUG_LEVEL > 1) || defined DBG_UTIL
#include <stdarg.h>
@@ -357,14 +358,13 @@ sal_Bool Sane::GetOptionValue( int n, OString& rRet )
sal_Bool bSuccess = sal_False;
if( ! maHandle || mppOptions[n]->type != SANE_TYPE_STRING )
return sal_False;
- char* pRet = new char[mppOptions[n]->size+1];
- SANE_Status nStatus = ControlOption( n, SANE_ACTION_GET_VALUE, pRet );
+ boost::scoped_array<char> pRet(new char[mppOptions[n]->size+1]);
+ SANE_Status nStatus = ControlOption( n, SANE_ACTION_GET_VALUE, pRet.get() );
if( nStatus == SANE_STATUS_GOOD )
{
bSuccess = sal_True;
- rRet = pRet;
+ rRet = pRet.get();
}
- delete [] pRet;
return bSuccess;
}
@@ -376,8 +376,8 @@ sal_Bool Sane::GetOptionValue( int n, double& rRet, int nElement )
mppOptions[n]->type != SANE_TYPE_FIXED ) )
return sal_False;
- SANE_Word* pRet = new SANE_Word[mppOptions[n]->size/sizeof(SANE_Word)];
- SANE_Status nStatus = ControlOption( n, SANE_ACTION_GET_VALUE, pRet );
+ boost::scoped_array<SANE_Word> pRet(new SANE_Word[mppOptions[n]->size/sizeof(SANE_Word)]);
+ SANE_Status nStatus = ControlOption( n, SANE_ACTION_GET_VALUE, pRet.get() );
if( nStatus == SANE_STATUS_GOOD )
{
bSuccess = sal_True;
@@ -386,7 +386,6 @@ sal_Bool Sane::GetOptionValue( int n, double& rRet, int nElement )
else
rRet = SANE_UNFIX( pRet[nElement] );
}
- delete [] pRet;
return bSuccess;
}
@@ -396,13 +395,10 @@ sal_Bool Sane::GetOptionValue( int n, double* pSet )
mppOptions[n]->type == SANE_TYPE_INT ) )
return sal_False;
- SANE_Word* pFixedSet = new SANE_Word[mppOptions[n]->size/sizeof(SANE_Word)];
- SANE_Status nStatus = ControlOption( n, SANE_ACTION_GET_VALUE, pFixedSet );
+ boost::scoped_array<SANE_Word> pFixedSet(new SANE_Word[mppOptions[n]->size/sizeof(SANE_Word)]);
+ SANE_Status nStatus = ControlOption( n, SANE_ACTION_GET_VALUE, pFixedSet.get() );
if( nStatus != SANE_STATUS_GOOD )
- {
- delete [] pFixedSet;
return sal_False;
- }
for( size_t i = 0; i <mppOptions[n]->size/sizeof(SANE_Word); i++ )
{
if( mppOptions[n]->type == SANE_TYPE_FIXED )
@@ -410,7 +406,6 @@ sal_Bool Sane::GetOptionValue( int n, double* pSet )
else
pSet[i] = (double) pFixedSet[i];
}
- delete [] pFixedSet;
return sal_True;
}
@@ -447,15 +442,14 @@ sal_Bool Sane::SetOptionValue( int n, double fSet, int nElement )
SANE_Status nStatus;
if( mppOptions[n]->size/sizeof(SANE_Word) > 1 )
{
- SANE_Word* pSet = new SANE_Word[mppOptions[n]->size/sizeof(SANE_Word)];
- nStatus = ControlOption( n, SANE_ACTION_GET_VALUE, pSet );
+ boost::scoped_array<SANE_Word> pSet(new SANE_Word[mppOptions[n]->size/sizeof(SANE_Word)]);
+ nStatus = ControlOption( n, SANE_ACTION_GET_VALUE, pSet.get() );
if( nStatus == SANE_STATUS_GOOD )
{
pSet[nElement] = mppOptions[n]->type == SANE_TYPE_INT ?
(SANE_Word)fSet : SANE_FIX( fSet );
- nStatus = ControlOption( n, SANE_ACTION_SET_VALUE, pSet );
+ nStatus = ControlOption( n, SANE_ACTION_SET_VALUE, pSet.get() );
}
- delete [] pSet;
}
else
{
@@ -475,7 +469,7 @@ sal_Bool Sane::SetOptionValue( int n, double* pSet )
if( ! maHandle || ( mppOptions[n]->type != SANE_TYPE_INT &&
mppOptions[n]->type != SANE_TYPE_FIXED ) )
return sal_False;
- SANE_Word* pFixedSet = new SANE_Word[mppOptions[n]->size/sizeof(SANE_Word)];
+ boost::scoped_array<SANE_Word> pFixedSet(new SANE_Word[mppOptions[n]->size/sizeof(SANE_Word)]);
for( size_t i = 0; i < mppOptions[n]->size/sizeof(SANE_Word); i++ )
{
if( mppOptions[n]->type == SANE_TYPE_FIXED )
@@ -483,8 +477,7 @@ sal_Bool Sane::SetOptionValue( int n, double* pSet )
else
pFixedSet[i] = (SANE_Word)pSet[i];
}
- SANE_Status nStatus = ControlOption( n, SANE_ACTION_SET_VALUE, pFixedSet );
- delete [] pFixedSet;
+ SANE_Status nStatus = ControlOption( n, SANE_ACTION_SET_VALUE, pFixedSet.get() );
if( nStatus != SANE_STATUS_GOOD )
return sal_False;
return sal_True;
diff --git a/extensions/source/scanner/sanedlg.cxx b/extensions/source/scanner/sanedlg.cxx
index 79efa8a..01f07fe 100644
--- a/extensions/source/scanner/sanedlg.cxx
+++ b/extensions/source/scanner/sanedlg.cxx
@@ -28,6 +28,7 @@
#include <math.h>
#include <sal/macros.h>
#include <rtl/strbuf.hxx>
+#include <boost/scoped_array.hpp>
ResId SaneResId( sal_uInt32 nID )
{
@@ -439,20 +440,17 @@ IMPL_LINK( SaneDlg, ClickBtnHdl, Button*, pButton )
case SANE_TYPE_INT:
{
int nElements = mrSane.GetOptionElements( mnCurrentOption );
- double* x = new double[ nElements ];
- double* y = new double[ nElements ];
+ boost::scoped_array<double> x(new double[ nElements ]);
+ boost::scoped_array<double> y(new double[ nElements ]);
for( int i = 0; i < nElements; i++ )
x[ i ] = (double)i;
- mrSane.GetOptionValue( mnCurrentOption, y );
+ mrSane.GetOptionValue( mnCurrentOption, y.get() );
- GridWindow aGrid( x, y, nElements, this );
+ GridWindow aGrid( x.get(), y.get(), nElements, this );
aGrid.SetText( mrSane.GetOptionName( mnCurrentOption ) );
aGrid.setBoundings( 0, mfMin, nElements, mfMax );
if( aGrid.Execute() && aGrid.getNewYValues() )
mrSane.SetOptionValue( mnCurrentOption, aGrid.getNewYValues() );
-
- delete [] x;
- delete [] y;
}
break;
case SANE_TYPE_BOOL:
More information about the Libreoffice-commits
mailing list