summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2014-05-27 10:30:05 +0200
committerStephan Bergmann <sbergman@redhat.com>2014-05-28 08:16:52 +0200
commitc63dbc56f01cd0fc4e0fa3d6daf536e0dfb3c70b (patch)
treec9c22a394a8b5331b9c879ab125b2565073d08ae /filter
parente665a1b5212b529673d6e9dec3e29e6dae0f0fe8 (diff)
Fix memory leak (as observed with CppunitTest_filter_ras_test)
(cherry picked from commit ba00f596cfbb78046e705f1d45264951bf03a9a1) Change-Id: Id3fa526f01ab7dae72beb311fe0774ba1f77d8a0
Diffstat (limited to 'filter')
-rw-r--r--filter/source/graphicfilter/iras/iras.cxx31
1 files changed, 13 insertions, 18 deletions
diff --git a/filter/source/graphicfilter/iras/iras.cxx b/filter/source/graphicfilter/iras/iras.cxx
index 9f71ab72c36f..c58bd4650477 100644
--- a/filter/source/graphicfilter/iras/iras.cxx
+++ b/filter/source/graphicfilter/iras/iras.cxx
@@ -44,7 +44,6 @@ private:
bool mbStatus;
Bitmap maBmp;
- BitmapWriteAccess* mpAcc;
sal_uInt32 mnWidth, mnHeight; // Bildausmass in Pixeln
sal_uInt16 mnDstBitsPerPix;
sal_uInt16 mnDstColors;
@@ -53,7 +52,7 @@ private:
sal_uInt8 mnRepCount, mnRepVal; // RLE Decoding
bool mbPalette;
- bool ImplReadBody();
+ bool ImplReadBody(BitmapWriteAccess * pAcc);
bool ImplReadHeader();
sal_uInt8 ImplGetByte();
@@ -68,7 +67,6 @@ public:
RASReader::RASReader(SvStream &rRAS)
: m_rRAS(rRAS)
, mbStatus(true)
- , mpAcc(NULL)
, mnWidth(0)
, mnHeight(0)
, mnDstBitsPerPix(0)
@@ -108,7 +106,8 @@ bool RASReader::ReadRAS(Graphic & rGraphic)
return false;
maBmp = Bitmap( Size( mnWidth, mnHeight ), mnDstBitsPerPix );
- if ( ( mpAcc = maBmp.AcquireWriteAccess() ) == 0 )
+ Bitmap::ScopedWriteAccess pAcc(maBmp);
+ if ( pAcc == 0 )
return false;
if ( mnDstBitsPerPix <= 8 ) // paletten bildchen
@@ -127,7 +126,7 @@ bool RASReader::ReadRAS(Graphic & rGraphic)
if ( ( mnDstColors >= 2 ) && ( ( mnColorMapSize % 3 ) == 0 ) )
{
- mpAcc->SetPaletteEntryCount( mnDstColors );
+ pAcc->SetPaletteEntryCount( mnDstColors );
sal_uInt16 i;
sal_uInt8 nRed[256], nGreen[256], nBlue[256];
for ( i = 0; i < mnDstColors; i++ ) m_rRAS.ReadUChar( nRed[ i ] );
@@ -135,7 +134,7 @@ bool RASReader::ReadRAS(Graphic & rGraphic)
for ( i = 0; i < mnDstColors; i++ ) m_rRAS.ReadUChar( nBlue[ i ] );
for ( i = 0; i < mnDstColors; i++ )
{
- mpAcc->SetPaletteColor( i, BitmapColor( nRed[ i ], nGreen[ i ], nBlue[ i ] ) );
+ pAcc->SetPaletteColor( i, BitmapColor( nRed[ i ], nGreen[ i ], nBlue[ i ] ) );
}
mbPalette = true;
}
@@ -149,11 +148,11 @@ bool RASReader::ReadRAS(Graphic & rGraphic)
if ( !mbPalette )
{
mnDstColors = 1 << mnDstBitsPerPix;
- mpAcc->SetPaletteEntryCount( mnDstColors );
+ pAcc->SetPaletteEntryCount( mnDstColors );
for ( sal_uInt16 i = 0; i < mnDstColors; i++ )
{
sal_uLong nCount = 255 - ( 255 * i / ( mnDstColors - 1 ) );
- mpAcc->SetPaletteColor( i, BitmapColor( (sal_uInt8)nCount, (sal_uInt8)nCount, (sal_uInt8)nCount ) );
+ pAcc->SetPaletteColor( i, BitmapColor( (sal_uInt8)nCount, (sal_uInt8)nCount, (sal_uInt8)nCount ) );
}
}
}
@@ -167,12 +166,8 @@ bool RASReader::ReadRAS(Graphic & rGraphic)
}
// Bitmap-Daten einlesen
- mbStatus = ImplReadBody();
+ mbStatus = ImplReadBody(pAcc.get());
- if ( mpAcc )
- {
- maBmp.ReleaseAccess( mpAcc ), mpAcc = NULL;
- }
if ( mbStatus )
rGraphic = maBmp;
@@ -219,7 +214,7 @@ bool RASReader::ImplReadHeader()
-bool RASReader::ImplReadBody()
+bool RASReader::ImplReadBody(BitmapWriteAccess * pAcc)
{
sal_uLong x, y;
sal_uInt8 nDat = 0;
@@ -233,7 +228,7 @@ bool RASReader::ImplReadBody()
{
if (!(x & 7))
nDat = ImplGetByte();
- mpAcc->SetPixelIndex( y, x,
+ pAcc->SetPixelIndex( y, x,
sal::static_int_cast< sal_uInt8 >(
nDat >> ( ( x & 7 ) ^ 7 )) );
}
@@ -247,7 +242,7 @@ bool RASReader::ImplReadBody()
for ( x = 0; x < mnWidth; x++ )
{
nDat = ImplGetByte();
- mpAcc->SetPixelIndex( y, x, nDat );
+ pAcc->SetPixelIndex( y, x, nDat );
}
if ( x & 1 ) ImplGetByte(); // WORD ALIGNMENT ???
}
@@ -274,7 +269,7 @@ bool RASReader::ImplReadBody()
nGreen = ImplGetByte();
nRed = ImplGetByte();
}
- mpAcc->SetPixel ( y, x, BitmapColor( nRed, nGreen, nBlue ) );
+ pAcc->SetPixel ( y, x, BitmapColor( nRed, nGreen, nBlue ) );
}
if ( x & 1 ) ImplGetByte(); // WORD ALIGNMENT ???
}
@@ -298,7 +293,7 @@ bool RASReader::ImplReadBody()
nGreen = ImplGetByte();
nRed = ImplGetByte();
}
- mpAcc->SetPixel ( y, x, BitmapColor( nRed, nGreen, nBlue ) );
+ pAcc->SetPixel ( y, x, BitmapColor( nRed, nGreen, nBlue ) );
}
}
break;