summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2014-04-02 16:08:04 +0900
committerTakeshi Abe <tabe@fixedpoint.jp>2014-04-02 16:09:11 +0900
commit8f7c677dbba29123c48778a1024a535f36bca183 (patch)
tree3123165f84a6bd7475d7311e75f59eed18b14450 /extensions
parentsw: unused include in objectformatterlayfrm (diff)
downloadcore-8f7c677dbba29123c48778a1024a535f36bca183.tar.gz
core-8f7c677dbba29123c48778a1024a535f36bca183.zip
Avoid possible resource leaks by boost::scoped_array
Change-Id: Ibf92b3098c50388d8b6d27f4476e613a1f8918b5
Diffstat (limited to 'extensions')
-rw-r--r--extensions/source/plugin/base/xplugin.cxx9
-rw-r--r--extensions/source/plugin/unx/mediator.cxx13
-rw-r--r--extensions/source/propctrlr/formcomponenthandler.cxx4
-rw-r--r--extensions/source/scanner/grid.cxx10
-rw-r--r--extensions/source/scanner/sane.cxx33
-rw-r--r--extensions/source/scanner/sanedlg.cxx12
6 files changed, 35 insertions, 46 deletions
diff --git a/extensions/source/plugin/base/xplugin.cxx b/extensions/source/plugin/base/xplugin.cxx
index 658d1ff8d52a..f85f7bd5f650 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 a4eea38df1b1..347f5e2a94d0 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 b6f5724f69ac..bc0f6e5234b2 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 5762bb593010..8f12b0643372 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 96b7716d9b14..f89895c93d7d 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 79efa8a9dd22..01f07fe00c56 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: