[Libreoffice-commits] core.git: filter/source

Caolán McNamara caolanm at redhat.com
Tue Feb 28 09:33:32 UTC 2017


 filter/source/graphicfilter/itiff/itiff.cxx |   30 +++++++++++++---------------
 1 file changed, 14 insertions(+), 16 deletions(-)

New commits:
commit 5ae0cb5618e53401da8ba3cec24ab3bf8ad24b05
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Feb 28 09:32:31 2017 +0000

    ofz#704 fix tiff leak
    
    Change-Id: Id43fd11b5503d1fdd967d146a71445e2fed4192f

diff --git a/filter/source/graphicfilter/itiff/itiff.cxx b/filter/source/graphicfilter/itiff/itiff.cxx
index 3fe1018..37ab726 100644
--- a/filter/source/graphicfilter/itiff/itiff.cxx
+++ b/filter/source/graphicfilter/itiff/itiff.cxx
@@ -91,7 +91,7 @@ private:
     sal_uLong               nGroup4Options;
     sal_uLong               nResolutionUnit;            // unit of fX/YResolution: 1=unknown, 2(default)=inch, 3=cm
     sal_uLong               nPredictor;
-    sal_uInt32*             pColorMap;                  // color palette
+    std::unique_ptr<sal_uInt32[]> xColorMap;            // color palette
     sal_uLong               nNumColors;                 // number of colors within the color palette
 
     sal_uLong               nPlanes;                    // number of layers within the Tiff file
@@ -161,7 +161,6 @@ public:
         , nGroup4Options(0)
         , nResolutionUnit(2)
         , nPredictor(0)
-        , pColorMap(nullptr)
         , nNumColors(0)
         , nPlanes(0)
         , nStripsPerPlane(0)
@@ -493,23 +492,23 @@ void TIFFReader::ReadTagData( sal_uInt16 nTagType, sal_uInt32 nDataLen)
             nNumColors= ( (sal_uLong)1 << nBitsPerSample );
             if ( nDataType == 3 && nNumColors <= 256)
             {
-                pColorMap = new sal_uInt32[256];
+                xColorMap.reset(new sal_uInt32[256]);
                 for ( i = 0; i < nNumColors; i++ )
-                    pColorMap[ i ] = 0;
+                    xColorMap[i] = 0;
                 for ( i = 0; i < nNumColors; i++ )
                 {
                     pTIFF->ReadUInt16( nVal );
-                    pColorMap[ i ] |= ( ( (sal_uInt32)nVal ) << 8 ) & 0x00ff0000;
+                    xColorMap[i] |= ( ( (sal_uInt32)nVal ) << 8 ) & 0x00ff0000;
                 }
                 for ( i = 0; i < nNumColors; i++ )
                 {
                     pTIFF->ReadUInt16( nVal );
-                    pColorMap[ i ] |= ( (sal_uInt32)nVal ) & 0x0000ff00;
+                    xColorMap[i] |= ( (sal_uInt32)nVal ) & 0x0000ff00;
                 }
                 for ( i = 0; i < nNumColors; i++ )
                 {
                     pTIFF->ReadUInt16( nVal );
-                    pColorMap[ i ] |= ( ( (sal_uInt32)nVal ) >> 8 ) & 0x000000ff;
+                    xColorMap[i] |= ( ( (sal_uInt32)nVal ) >> 8 ) & 0x000000ff;
                 }
             }
             else
@@ -1076,7 +1075,7 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY)
         }
     }
     else if ( ( nSamplesPerPixel == 2 ) && ( nBitsPerSample == 8 ) &&
-        ( nPlanarConfiguration == 1 ) && ( pColorMap == nullptr ) )               // grayscale
+        ( nPlanarConfiguration == 1 ) && !xColorMap )               // grayscale
     {
         if ( nMaxSampleValue > nMinSampleValue )
         {
@@ -1099,8 +1098,8 @@ void TIFFReader::MakePalCol()
     if ( nDstBitsPerPixel <= 8 )
     {
         sal_uLong i, nVal;
-        if  ( pColorMap == nullptr )
-            pColorMap = new sal_uInt32[256];
+        if  (!xColorMap)
+            xColorMap.reset(new sal_uInt32[256]);
         if ( nPhotometricInterpretation <= 1 )
         {
             nNumColors = (sal_uLong)1 << nBitsPerSample;
@@ -1112,15 +1111,15 @@ void TIFFReader::MakePalCol()
                 nVal = ( i * 255 / ( nNumColors - 1 ) ) & 0xff;
                 sal_uInt32 n0RGB = nVal | ( nVal << 8 ) | ( nVal << 16 );
                 if ( nPhotometricInterpretation == 1 )
-                    pColorMap[ i ] = n0RGB;
+                    xColorMap[i] = n0RGB;
                 else
-                    pColorMap[ nNumColors - i - 1 ] = n0RGB;
+                    xColorMap[nNumColors - i - 1] = n0RGB;
             }
         }
         for ( i = 0; i < nNumColors; i++ )
         {
-            pAcc->SetPaletteColor( (sal_uInt16)i, BitmapColor( (sal_uInt8)( pColorMap[ i ] >> 16 ),
-                (sal_uInt8)( pColorMap[ i ] >> 8 ), (sal_uInt8)pColorMap[ i ] ) );
+            pAcc->SetPaletteColor( (sal_uInt16)i, BitmapColor( (sal_uInt8)( xColorMap[ i ] >> 16 ),
+                (sal_uInt8)( xColorMap[ i ] >> 8 ), (sal_uInt8)xColorMap[ i ] ) );
         }
     }
 
@@ -1290,7 +1289,6 @@ bool TIFFReader::ReadTIFF(SvStream & rTIFF, Graphic & rGraphic )
                 nNumColors = 0;
 
                 pAcc = nullptr;
-                pColorMap = nullptr;
                 pStripOffsets = nullptr;
                 pStripByteCounts = nullptr;
                 pMap[ 0 ] = pMap[ 1 ] = pMap[ 2 ] = pMap[ 3 ] = nullptr;
@@ -1434,7 +1432,7 @@ bool TIFFReader::ReadTIFF(SvStream & rTIFF, Graphic & rGraphic )
             // Clean up:
             for ( i = 0; i < 4; i++ )
                 delete[] pMap[ i ];
-            delete[] pColorMap;
+            xColorMap.reset();
             delete[] pStripOffsets;
             delete[] pStripByteCounts;
         }


More information about the Libreoffice-commits mailing list