summaryrefslogtreecommitdiff
path: root/sax/source
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2014-04-24 00:09:19 +0900
committerTakeshi Abe <tabe@fixedpoint.jp>2014-04-24 00:13:28 +0900
commit1ec836760853e9e220d471cf39f2533f0828f00e (patch)
treeaa481fb529d129a16af492818f63858a1af757d8 /sax/source
parent2ea006fb605b886f9c9426783e4edf0de46c9af8 (diff)
Avoid possible memory leaks in case of exceptions
Change-Id: I047fd88a89900153089a55b6af123f11fb8bde55
Diffstat (limited to 'sax/source')
-rw-r--r--sax/source/expatwrap/saxwriter.cxx7
-rw-r--r--sax/source/expatwrap/xml2utf.cxx26
2 files changed, 13 insertions, 20 deletions
diff --git a/sax/source/expatwrap/saxwriter.cxx b/sax/source/expatwrap/saxwriter.cxx
index 140bcfbca9f2..4dee83d543aa 100644
--- a/sax/source/expatwrap/saxwriter.cxx
+++ b/sax/source/expatwrap/saxwriter.cxx
@@ -49,6 +49,7 @@ using namespace ::com::sun::star::util;
using namespace ::com::sun::star::io;
#include "xml2utf.hxx"
+#include <boost/scoped_array.hpp>
namespace com { namespace sun { namespace star { namespace uno {
class XComponentContext;
@@ -493,11 +494,11 @@ inline void SaxWriterHelper::insertIndentation(sal_uInt32 m_nLevel) throw( SAXEx
else
{
sal_uInt32 nCount(m_nLevel + 1);
- sal_Int8* pBytes = new sal_Int8[nCount];
+ boost::scoped_array<sal_Int8> pBytes(new sal_Int8[nCount]);
pBytes[0] = LINEFEED;
memset( &(pBytes[1]), 32, m_nLevel );
- AddBytes(mp_Sequence, nCurrentPos, pBytes, nCount);
- delete[] pBytes;
+ AddBytes(mp_Sequence, nCurrentPos, pBytes.get(), nCount);
+ pBytes.reset();
nLastLineFeedPos = nCurrentPos - nCount;
if (nCurrentPos == SEQUENCESIZE)
nCurrentPos = writeSequence();
diff --git a/sax/source/expatwrap/xml2utf.cxx b/sax/source/expatwrap/xml2utf.cxx
index 90e55dca6532..8a13823b98a6 100644
--- a/sax/source/expatwrap/xml2utf.cxx
+++ b/sax/source/expatwrap/xml2utf.cxx
@@ -32,6 +32,7 @@ using namespace ::com::sun::star::io;
#include "xml2utf.hxx"
+#include <boost/scoped_array.hpp>
namespace sax_expatwrap {
@@ -394,14 +395,14 @@ Sequence<sal_Unicode> Text2UnicodeConverter::convert( const Sequence<sal_Int8> &
Sequence<sal_Unicode> seqUnicode ( nSourceSize );
const sal_Int8 *pbSource = seqText.getConstArray();
- sal_Int8 *pbTempMem = 0;
+ boost::scoped_array<sal_Int8> pbTempMem;
if( m_seqSource.getLength() ) {
// put old rest and new byte sequence into one array
- pbTempMem = new sal_Int8[ nSourceSize ];
- memcpy( pbTempMem , m_seqSource.getConstArray() , m_seqSource.getLength() );
+ pbTempMem.reset(new sal_Int8[ nSourceSize ]);
+ memcpy( pbTempMem.get() , m_seqSource.getConstArray() , m_seqSource.getLength() );
memcpy( &(pbTempMem[ m_seqSource.getLength() ]) , seqText.getConstArray() , seqText.getLength() );
- pbSource = pbTempMem;
+ pbSource = pbTempMem.get();
// set to zero again
m_seqSource = Sequence< sal_Int8 >();
@@ -436,11 +437,6 @@ Sequence<sal_Unicode> Text2UnicodeConverter::convert( const Sequence<sal_Int8> &
memcpy( m_seqSource.getArray() , &(pbSource[nSourceCount]) , nSourceSize-nSourceCount );
}
-
- if( pbTempMem ) {
- delete [] pbTempMem;
- }
-
// set to correct unicode size
seqUnicode.realloc( nTargetCount );
@@ -471,7 +467,7 @@ Unicode2TextConverter::~Unicode2TextConverter()
Sequence<sal_Int8> Unicode2TextConverter::convert(const sal_Unicode *puSource , sal_Int32 nSourceSize)
{
- sal_Unicode *puTempMem = 0;
+ boost::scoped_array<sal_Unicode> puTempMem;
if( m_seqSource.getLength() ) {
// For surrogates !
@@ -479,15 +475,15 @@ Sequence<sal_Int8> Unicode2TextConverter::convert(const sal_Unicode *puSource ,
// In general when surrogates are used, they should be rarely
// cut off between two convert()-calls. So this code is used
// rarely and the extra copy is acceptable.
- puTempMem = new sal_Unicode[ nSourceSize + m_seqSource.getLength()];
- memcpy( puTempMem ,
+ puTempMem.reset(new sal_Unicode[ nSourceSize + m_seqSource.getLength()]);
+ memcpy( puTempMem.get() ,
m_seqSource.getConstArray() ,
m_seqSource.getLength() * sizeof( sal_Unicode ) );
memcpy(
&(puTempMem[ m_seqSource.getLength() ]) ,
puSource ,
nSourceSize*sizeof( sal_Unicode ) );
- puSource = puTempMem;
+ puSource = puTempMem.get();
nSourceSize += m_seqSource.getLength();
m_seqSource = Sequence< sal_Unicode > ();
@@ -539,10 +535,6 @@ Sequence<sal_Int8> Unicode2TextConverter::convert(const sal_Unicode *puSource ,
(nSourceSize - nSourceCount) * sizeof( sal_Unicode ) );
}
- if( puTempMem ) {
- delete [] puTempMem;
- }
-
// reduce the size of the buffer (fast, no copy necessary)
seqText.realloc( nTargetCount );