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

Takeshi Abe tabe at fixedpoint.jp
Wed Mar 12 15:55:08 PDT 2014


 vcl/source/filter/sgfbram.cxx    |   22 ++++++++---------
 vcl/source/filter/sgvspln.cxx    |   37 +++++++++++-----------------
 vcl/source/filter/sgvtext.cxx    |   13 ++++------
 vcl/source/filter/wmf/emfwr.cxx  |   11 +++-----
 vcl/source/filter/wmf/enhwmf.cxx |   31 ++++++++++--------------
 vcl/source/filter/wmf/winwmf.cxx |   50 +++++++++++++++++----------------------
 vcl/source/filter/wmf/wmfwr.cxx  |   16 ++++++------
 7 files changed, 82 insertions(+), 98 deletions(-)

New commits:
commit 7225de6c5c3c5881c1edf60cf9d088043bf30b51
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Thu Mar 13 06:58:17 2014 +0900

    Avoid possible resource leaks by boost::scoped_array
    
    Change-Id: Ibc90eba9f336b649a968f584f2b36139c847d348

diff --git a/vcl/source/filter/sgfbram.cxx b/vcl/source/filter/sgfbram.cxx
index bacb9a4..1c69101 100644
--- a/vcl/source/filter/sgfbram.cxx
+++ b/vcl/source/filter/sgfbram.cxx
@@ -26,6 +26,7 @@
 #include <vcl/virdev.hxx>
 #include "sgffilt.hxx"
 #include "sgfbram.hxx"
+#include <boost/scoped_array.hpp>
 
 SgfHeader::SgfHeader()
 {
@@ -209,7 +210,7 @@ bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&)
     sal_uInt16         i,j,k;              // column/row/plane counter
     sal_uInt16         a,b;                // helper variables
     sal_uInt8           pl1 = 0;            // masks for the planes
-    sal_uInt8*          pBuf=NULL;          // buffer for a pixel row
+    boost::scoped_array<sal_uInt8> pBuf;   // buffer for a pixel row
     PcxExpand      aPcx;
     sal_uLong          nOfs;
     sal_uInt8           cRGB[4];
@@ -233,11 +234,11 @@ bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&)
     aBmpInfo.yDpmm=0;
     aBmpInfo.ColUsed=0;
     aBmpInfo.ColMust=0;
-    pBuf=new sal_uInt8[nWdtOut];
+    pBuf.reset(new sal_uInt8[nWdtOut]);
     if (!pBuf) return false;       // error: no more memory available
     WriteBmpFileHeader( rOut, aBmpHead );
     WriteBmpInfoHeader( rOut, aBmpInfo );
-    memset(pBuf,0,nWdtOut);        // fill buffer with zeroes
+    memset(pBuf.get(),0,nWdtOut);        // fill buffer with zeroes
 
     if (nColors==2)
     {
@@ -246,14 +247,14 @@ bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&)
         WriteRGBQuad( rOut, RGBQuad(0xFF,0xFF,0xFF) ); // white
         nOfs=rOut.Tell();
         for (j=0;j<rHead.Ysize;j++)
-            rOut.Write((char*)pBuf,nWdtOut);  // fill file with zeroes
+            rOut.Write((char*)pBuf.get(),nWdtOut);  // fill file with zeroes
         for (j=0;j<rHead.Ysize;j++) {
             for(i=0;i<nWdtInp;i++) {
                 pBuf[i]=aPcx.GetByte(rInp);
             }
             for(i=nWdtInp;i<nWdtOut;i++) pBuf[i]=0;     // up to 3 bytes
             rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // write backwards
-            rOut.Write((char*)pBuf,nWdtOut);
+            rOut.Write((char*)pBuf.get(),nWdtOut);
         }
     } else if (nColors==16) {
         sal_uInt8 pl2= 0;     // planes' masks
@@ -277,9 +278,9 @@ bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&)
 
         nOfs=rOut.Tell();
         for (j=0;j<rHead.Ysize;j++)
-            rOut.Write((char*)pBuf,nWdtOut);  // fill file with zeroes
+            rOut.Write((char*)pBuf.get(),nWdtOut);  // fill file with zeroes
         for (j=0;j<rHead.Ysize;j++) {
-            memset(pBuf,0,nWdtOut);
+            memset(pBuf.get(),0,nWdtOut);
             for(k=0;k<4;k++) {
                 if (k==0) {
                     pl1=0x10; pl2=0x01;
@@ -301,7 +302,7 @@ bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&)
             }
             for(i=nWdtInp*4;i<nWdtOut;i++) pBuf[i]=0;            // up to 3 bytes
             rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // write backwards
-            rOut.Write((char*)pBuf,nWdtOut);
+            rOut.Write((char*)pBuf.get(),nWdtOut);
         }
     } else if (nColors==256) {
         cRGB[3]=0;                      // fourth palette entry for BMP
@@ -315,16 +316,15 @@ bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&)
 
         nOfs=rOut.Tell();
         for (j=0;j<rHead.Ysize;j++)
-            rOut.Write((char*)pBuf,nWdtOut);  // fill file with zeroes
+            rOut.Write((char*)pBuf.get(),nWdtOut);  // fill file with zeroes
         for (j=0;j<rHead.Ysize;j++) {
             for(i=0;i<rHead.Xsize;i++)
                 pBuf[i]=aPcx.GetByte(rInp);
             for(i=rHead.Xsize;i<nWdtOut;i++) pBuf[i]=0;          // up to 3 bytes
             rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // write backwards
-            rOut.Write((char*)pBuf,nWdtOut);
+            rOut.Write((char*)pBuf.get(),nWdtOut);
         }
     }
-    delete[] pBuf;
     return true;
 }
 
diff --git a/vcl/source/filter/sgvspln.cxx b/vcl/source/filter/sgvspln.cxx
index 167a167..b95fc50 100644
--- a/vcl/source/filter/sgvspln.cxx
+++ b/vcl/source/filter/sgvspln.cxx
@@ -22,6 +22,7 @@
 
 
 #include <tools/poly.hxx>
+#include <boost/scoped_array.hpp>
 
 extern "C" {
 
@@ -418,17 +419,17 @@ sal_uInt16 NaturalSpline(sal_uInt16 n, double* x, double* y,
                      double* b, double* c, double* d)
 {
     sal_uInt16  i;
-    double* a;
-    double* h;
+    boost::scoped_array<double> a;
+    boost::scoped_array<double> h;
     sal_uInt16  error;
 
     if (n<2) return 1;
     if ( (MargCond & ~3) ) return 2;
-    a=new double[n+1];
-    h=new double[n+1];
+    a.reset(new double[n+1]);
+    h.reset(new double[n+1]);
     for (i=0;i<n;i++) {
         h[i]=x[i+1]-x[i];
-        if (h[i]<=0.0) { delete[] a; delete[] h; return 1; }
+        if (h[i]<=0.0) return 1;
     }
     for (i=0;i<n-1;i++) {
         a[i]=3.0*((y[i+2]-y[i+1])/h[i+1]-(y[i+1]-y[i])/h[i]);
@@ -470,8 +471,8 @@ sal_uInt16 NaturalSpline(sal_uInt16 n, double* x, double* y,
     if (n==2) {
         c[1]=a[0]/d[0];
     } else {
-        error=TriDiagGS(false,n-1,b,d,c,a);
-        if (error!=0) { delete[] a; delete[] h; return error+2; }
+        error=TriDiagGS(false,n-1,b,d,c,a.get());
+        if (error!=0) return error+2;
         for (i=0;i<n-1;i++) c[i+1]=a[i];
     }
     switch (MargCond) {
@@ -503,8 +504,6 @@ sal_uInt16 NaturalSpline(sal_uInt16 n, double* x, double* y,
         b[i]=(y[i+1]-y[i])/h[i]-h[i]*(c[i+1]+2.0*c[i])/3.0;
         d[i]=(c[i+1]-c[i])/(3.0*h[i]);
     }
-    delete[] a;
-    delete[] h;
     return 0;
 }
 
@@ -525,18 +524,18 @@ sal_uInt16 PeriodicSpline(sal_uInt16 n, double* x, double* y,
     sal_uInt16  Error;
     sal_uInt16  i,im1,nm1; //integer
     double  hr,hl;
-    double* a;
-    double* lowrow;
-    double* ricol;
+    boost::scoped_array<double> a;
+    boost::scoped_array<double> lowrow;
+    boost::scoped_array<double> ricol;
 
     if (n<2) return 4;
     nm1=n-1;
     for (i=0;i<=nm1;i++) if (x[i+1]<=x[i]) return 2; // should be strictly monotonically decreasing!
     if (y[n]!=y[0]) return 3; // begin and end should be equal!
 
-    a     =new double[n+1];
-    lowrow=new double[n+1];
-    ricol =new double[n+1];
+    a.reset(new double[n+1]);
+    lowrow.reset(new double[n+1]);
+    ricol.reset(new double[n+1]);
 
     if (n==2) {
         c[1]=3.0*((y[2]-y[1])/(x[2]-x[1]));
@@ -560,12 +559,9 @@ sal_uInt16 PeriodicSpline(sal_uInt16 n, double* x, double* y,
         lowrow[0]=hr;
         ricol[0]=hr;
         a[nm1]=3.0*((y[1]-y[0])/hr-(y[n]-y[nm1])/hl);
-        Error=ZyklTriDiagGS(false,n,b,d,c,lowrow,ricol,a);
+        Error=ZyklTriDiagGS(false,n,b,d,c,lowrow.get(),ricol.get(),a.get());
         if ( Error != 0 )
         {
-            delete[] a;
-            delete[] lowrow;
-            delete[] ricol;
             return(Error+4);
         }
         for (i=0;i<=nm1;i++) c[i+1]=a[i];
@@ -577,9 +573,6 @@ sal_uInt16 PeriodicSpline(sal_uInt16 n, double* x, double* y,
         b[i]=b[i]-hl*(c[i+1]+2.0*c[i])/3.0;
         d[i]=(c[i+1]-c[i])/hl/3.0;
     }
-    delete[] a;
-    delete[] lowrow;
-    delete[] ricol;
     return 0;
 }
 
diff --git a/vcl/source/filter/sgvtext.cxx b/vcl/source/filter/sgvtext.cxx
index 3262cdc..e942e89 100644
--- a/vcl/source/filter/sgvtext.cxx
+++ b/vcl/source/filter/sgvtext.cxx
@@ -28,6 +28,7 @@
 #include "sgffilt.hxx"
 #include "sgfbram.hxx"
 #include "sgvmain.hxx"
+#include <boost/scoped_array.hpp>
 
 extern SgfFontLst* pSgfFonts;
 
@@ -906,8 +907,8 @@ void TextType::Draw(OutputDevice& rOut)
     bool   Ende = false;
     sal_uInt16 lc;
     bool   TextFit;
-    short* xLine;
-    UCHAR* cLine;   // Buffer for FormatLine
+    boost::scoped_array<short> xLine;
+    boost::scoped_array<UCHAR> cLine;   // Buffer for FormatLine
     sal_uInt16 FitXMul;
     sal_uInt16 FitXDiv;
     sal_uInt16 FitYMul;
@@ -916,8 +917,8 @@ void TextType::Draw(OutputDevice& rOut)
     UCHAR* Buf=Buffer; // pointer to the letters
 
     pSgfFonts->ReadList();
-    xLine=new short[ChrXPosArrSize];
-    cLine=new UCHAR[CharLineSize];
+    xLine.reset(new short[ChrXPosArrSize]);
+    cLine.reset(new UCHAR[CharLineSize]);
 
     TextFit=(Flags & TextFitBits)!=0;
     bool LineFit=((Flags & TextFitZBit)!=0);  // FitSize.x=0? or flags -> strech each line
@@ -951,7 +952,7 @@ void TextType::Draw(OutputDevice& rOut)
 
     do {
         T2=T1; Index2=Index1;
-        FormatLine(Buf,Index2,T,T2,xSize,xSAdj,xLine,l,sn,cs,cLine,LineFit);
+        FormatLine(Buf,Index2,T,T2,xSize,xSAdj,xLine.get(),l,sn,cs,cLine.get(),LineFit);
         Fehler=(Index2==Index1);
         if (!Fehler) {
             lc=GetLineFeed(Buf,Index1,T,T1,l,LF,MaxGrad);
@@ -996,8 +997,6 @@ void TextType::Draw(OutputDevice& rOut)
             } // if ObjMin.y+yPos<=Obj_Max.y
         } // if !Fehler
     } while (c!=TextEnd && !Ende && !Fehler);
-    delete[] cLine;
-    delete[] xLine;
 }
 
 // End of DrawText.Pas
diff --git a/vcl/source/filter/wmf/emfwr.cxx b/vcl/source/filter/wmf/emfwr.cxx
index 6d557e7..abd2ada 100644
--- a/vcl/source/filter/wmf/emfwr.cxx
+++ b/vcl/source/filter/wmf/emfwr.cxx
@@ -28,6 +28,7 @@
 #include <basegfx/polygon/b2dpolypolygon.hxx>
 #include <vcl/lineinfo.hxx>
 #include <vcl/dibtools.hxx>
+#include <boost/scoped_array.hpp>
 
 #define WIN_EMR_POLYGON                     3
 #define WIN_EMR_POLYLINE                    4
@@ -878,21 +879,20 @@ void EMFWriter::ImplWriteTextRecord( const Point& rPos, const OUString rText, co
     if( nLen )
     {
         sal_uInt32  nNormWidth;
-        sal_Int32*  pOwnArray;
+        boost::scoped_array<sal_Int32> pOwnArray;
         sal_Int32*  pDX;
 
         // get text sizes
         if( pDXArray )
         {
-            pOwnArray = NULL;
             nNormWidth = maVDev.GetTextWidth( rText );
             pDX = (sal_Int32*) pDXArray;
         }
         else
         {
-            pOwnArray = new sal_Int32[ nLen ];
-            nNormWidth = maVDev.GetTextArray( rText, pOwnArray );
-            pDX = pOwnArray;
+            pOwnArray.reset(new sal_Int32[ nLen ]);
+            nNormWidth = maVDev.GetTextArray( rText, pOwnArray.get() );
+            pDX = pOwnArray.get();
         }
 
         if( nLen > 1 )
@@ -939,7 +939,6 @@ void EMFWriter::ImplWriteTextRecord( const Point& rPos, const OUString rText, co
         }
 
         ImplEndRecord();
-        delete[] pOwnArray;
     }
 }
 
diff --git a/vcl/source/filter/wmf/enhwmf.cxx b/vcl/source/filter/wmf/enhwmf.cxx
index c4e5719..6c58c94 100644
--- a/vcl/source/filter/wmf/enhwmf.cxx
+++ b/vcl/source/filter/wmf/enhwmf.cxx
@@ -23,6 +23,7 @@
 #include <basegfx/matrix/b2dhommatrix.hxx>
 #include <boost/bind.hpp>
 #include <vcl/dibtools.hxx>
+#include <boost/scoped_array.hpp>
 
 using namespace std;
 
@@ -373,7 +374,7 @@ void EnhWMFReader::ReadAndDrawPolyLine()
          ( static_cast< sal_uInt32 >( nPoly ) * sizeof(sal_uInt16) ) <= ( nEndPos - pWMF->Tell() )
        )
     {
-        sal_uInt16* pnPoints = new sal_uInt16[ nPoly ];
+        boost::scoped_array<sal_uInt16> pnPoints(new sal_uInt16[ nPoly ]);
         for ( i = 0; i < nPoly && pWMF->good(); i++ )
         {
             pWMF->ReadUInt32( nPoints );
@@ -385,7 +386,6 @@ void EnhWMFReader::ReadAndDrawPolyLine()
             Polygon aPolygon = ReadPolygon<T>(0, pnPoints[i]);
             pOut->DrawPolyLine( aPolygon, false, bRecordPath );
         }
-        delete[] pnPoints;
     }
 }
 
@@ -418,7 +418,7 @@ void EnhWMFReader::ReadAndDrawPolyPolygon()
         ( (  nPoly * sizeof( sal_uInt16 ) ) <= ( nEndPos - pWMF->Tell() ) ))
     {
         // Get number of points in each polygon
-        sal_uInt16 * pnPoints = new sal_uInt16[ nPoly ];
+        boost::scoped_array<sal_uInt16> pnPoints(new sal_uInt16[ nPoly ]);
         for (sal_uInt32 i = 0; i < nPoly && pWMF->good(); ++i)
         {
             sal_uInt32 nPoints(0);
@@ -432,7 +432,7 @@ void EnhWMFReader::ReadAndDrawPolyPolygon()
             for (sal_uInt32 i = 0; i < nPoly && pWMF->good(); ++i)
             {
                 const sal_uInt16 nPointCount(pnPoints[i]);
-                Point* pPtAry = new Point[nPointCount];
+                boost::scoped_array<Point> pPtAry(new Point[nPointCount]);
                 for (sal_uInt16 j = 0; j < nPointCount && pWMF->good(); ++j)
                 {
                     T nX(0), nY(0);
@@ -441,13 +441,11 @@ void EnhWMFReader::ReadAndDrawPolyPolygon()
                     ++nReadPoints;
                 }
 
-                aPolyPoly.Insert(Polygon(nPointCount, pPtAry));
-                delete[] pPtAry;
+                aPolyPoly.Insert(Polygon(nPointCount, pPtAry.get()));
             }
 
             pOut->DrawPolyPolygon( aPolyPoly, bRecordPath );
         }
-        delete[] pnPoints;
 
         OSL_ENSURE(nReadPoints == nGesPoints, "The number Points processed from EMR_POLYPOLYGON is unequal imported number (!)");
 
@@ -1284,10 +1282,10 @@ bool EnhWMFReader::ReadEnhWMF()
                         {
                             if ( nLen <= static_cast<sal_Int32>( nEndPos - pWMF->Tell() ) )
                             {
-                                sal_Char* pBuf = new sal_Char[ nLen ];
-                                pWMF->Read( pBuf, nLen );
-                                aText = OUString( pBuf, (sal_uInt16)nLen, pOut->GetCharSet() );
-                                delete[] pBuf;
+                                boost::scoped_array<sal_Char> pBuf(new sal_Char[ nLen ]);
+                                pWMF->Read( pBuf.get(), nLen );
+                                aText = OUString( pBuf.get(), (sal_uInt16)nLen, pOut->GetCharSet() );
+                                pBuf.reset();
 
                                 if ( aText.getLength() != nLen )
                                 {
@@ -1310,19 +1308,18 @@ bool EnhWMFReader::ReadEnhWMF()
                         {
                             if ( ( nLen * sizeof(sal_Unicode) ) <= ( nEndPos - pWMF->Tell() ) )
                             {
-                                sal_Unicode* pBuf = new sal_Unicode[ nLen ];
-                                pWMF->Read( pBuf, nLen << 1 );
+                                boost::scoped_array<sal_Unicode> pBuf(new sal_Unicode[ nLen ]);
+                                pWMF->Read( pBuf.get(), nLen << 1 );
 #ifdef OSL_BIGENDIAN
-                                sal_Char nTmp, *pTmp = (sal_Char*)( pBuf + nLen );
-                                while ( pTmp-- != (sal_Char*)pBuf )
+                                sal_Char nTmp, *pTmp = (sal_Char*)( pBuf.get() + nLen );
+                                while ( pTmp-- != (sal_Char*)pBuf.get() )
                                 {
                                     nTmp = *pTmp--;
                                     pTmp[ 1 ] = *pTmp;
                                     *pTmp = nTmp;
                                 }
 #endif
-                                aText = OUString(pBuf, nLen);
-                                delete[] pBuf;
+                                aText = OUString(pBuf.get(), nLen);
                             }
                         }
                         pOut->DrawText( aPos, aText, pDX, bRecordPath, nGfxMode );
diff --git a/vcl/source/filter/wmf/winwmf.cxx b/vcl/source/filter/wmf/winwmf.cxx
index 52c34a4..792f484 100644
--- a/vcl/source/filter/wmf/winwmf.cxx
+++ b/vcl/source/filter/wmf/winwmf.cxx
@@ -27,6 +27,7 @@
 #include <osl/endian.h>
 #include <vcl/svapp.hxx>
 #include <vcl/dibtools.hxx>
+#include <boost/scoped_array.hpp>
 
 // MS Windows defines
 
@@ -442,10 +443,10 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
             pWMF->ReadUInt16( nLength );
             if ( nLength )
             {
-                char*   pChar = new char[ ( nLength + 1 ) &~ 1 ];
-                pWMF->Read( pChar, ( nLength + 1 ) &~ 1 );
-                OUString aText( pChar, nLength, pOut->GetCharSet() );
-                delete[] pChar;
+                boost::scoped_array<char> pChar(new char[ ( nLength + 1 ) &~ 1 ]);
+                pWMF->Read( pChar.get(), ( nLength + 1 ) &~ 1 );
+                OUString aText( pChar.get(), nLength, pOut->GetCharSet() );
+                pChar.reset();
                 Point aPosition( ReadYX() );
                 pOut->DrawText( aPosition, aText );
             }
@@ -458,7 +459,7 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
             sal_Int32   nRecordPos, nRecordSize = 0, nOriginalTextLen, nNewTextLen;
             Point       aPosition;
             Rectangle   aRect;
-            sal_Int32*  pDXAry = NULL;
+            boost::scoped_array<sal_Int32> pDXAry;
 
             pWMF->SeekRel(-6);
             nRecordPos = pWMF->Tell();
@@ -483,11 +484,11 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
                     const Point aPt2( ReadPoint() );
                     aRect = Rectangle( aPt1, aPt2 );
                 }
-                char* pChar = new char[ ( nOriginalTextLen + 1 ) &~ 1 ];
-                pWMF->Read( pChar, ( nOriginalTextLen + 1 ) &~ 1 );
-                OUString aText( pChar, (sal_uInt16)nOriginalTextLen, pOut->GetCharSet() );// after this conversion the text may contain
+                boost::scoped_array<char> pChar(new char[ ( nOriginalTextLen + 1 ) &~ 1 ]);
+                pWMF->Read( pChar.get(), ( nOriginalTextLen + 1 ) &~ 1 );
+                OUString aText( pChar.get(), (sal_uInt16)nOriginalTextLen, pOut->GetCharSet() );// after this conversion the text may contain
                 nNewTextLen = aText.getLength();                                          // less character (japanese version), so the
-                delete[] pChar;                                                         // dxAry will not fit
+                pChar.reset();                                                         // dxAry will not fit
 
                 if ( nNewTextLen )
                 {
@@ -500,7 +501,7 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
                     {
                         sal_Int16 nDx = 0, nDxTmp = 0;
                         sal_uInt16 i; //needed just outside the for
-                        pDXAry = new sal_Int32[ nNewTextLen ];
+                        pDXAry.reset(new sal_Int32[ nNewTextLen ]);
                         for (i = 0; i < nNewTextLen; i++ )
                         {
                             if ( pWMF->Tell() >= nMaxStreamPos )
@@ -528,13 +529,11 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
                             bUseDXAry = true;
                     }
                     if ( pDXAry && bUseDXAry )
-                        pOut->DrawText( aPosition, aText, pDXAry );
+                        pOut->DrawText( aPosition, aText, pDXAry.get() );
                     else
                         pOut->DrawText( aPosition, aText );
                 }
             }
-            delete[] pDXAry;
-
         }
         break;
 
@@ -939,7 +938,7 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
 #else
                                 sal_uInt32 nCheckSum = rtl_crc32( 0, &nEsc, 4 );
 #endif
-                                sal_Int8* pData = NULL;
+                                boost::scoped_array<sal_Int8> pData;
 
                                 if ( ( static_cast< sal_uInt64 >( nEscLen ) + pWMF->Tell() ) > nMetaRecEndPos )
                                 {
@@ -948,9 +947,9 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
                                 }
                                 if ( nEscLen > 0 )
                                 {
-                                    pData = new sal_Int8[ nEscLen ];
-                                    pWMF->Read( pData, nEscLen );
-                                    nCheckSum = rtl_crc32( nCheckSum, pData, nEscLen );
+                                    pData.reset(new sal_Int8[ nEscLen ]);
+                                    pWMF->Read( pData.get(), nEscLen );
+                                    nCheckSum = rtl_crc32( nCheckSum, pData.get(), nEscLen );
                                 }
                                 if ( nCheck == nCheckSum )
                                 {
@@ -964,9 +963,9 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
                                                 Point  aPt;
                                                 OUString aString;
                                                 sal_uInt32  nStringLen, nDXCount;
-                                                sal_Int32* pDXAry = NULL;
+                                                boost::scoped_array<sal_Int32> pDXAry;
                                                 SvMemoryStream aMemoryStream( nEscLen );
-                                                aMemoryStream.Write( pData, nEscLen );
+                                                aMemoryStream.Write( pData.get(), nEscLen );
                                                 aMemoryStream.Seek( STREAM_SEEK_TO_BEGIN );
                                                 //#fdo39428 SvStream no longer supports operator>>(long&)
                                                 sal_Int32 nTmpX(0), nTmpY(0);
@@ -984,19 +983,17 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
                                                     if ( ( static_cast< sal_uInt64 >( nDXCount ) * sizeof( sal_Int32 ) ) >= ( nEscLen - aMemoryStream.Tell() ) )
                                                         nDXCount = 0;
                                                     if ( nDXCount )
-                                                        pDXAry = new sal_Int32[ nDXCount ];
+                                                        pDXAry.reset(new sal_Int32[ nDXCount ]);
                                                     for  (sal_uInt32 i = 0; i < nDXCount; i++ )
                                                         aMemoryStream.ReadInt32( pDXAry[ i ] );
                                                     aMemoryStream.ReadUInt32( nSkipActions );
-                                                    pOut->DrawText( aPt, aString, pDXAry );
-                                                    delete[] pDXAry;
+                                                    pOut->DrawText( aPt, aString, pDXAry.get() );
                                                 }
                                             }
                                         }
                                         break;
                                     }
                                 }
-                                delete[] pData;
                             }
                         }
                     }
@@ -1037,11 +1034,10 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
 
                             if( pEMFStream )
                             {
-                                sal_Int8* pBuf = new sal_Int8[ nCurRecSize ];
-                                sal_uInt32 nCount = pWMF->Read( pBuf, nCurRecSize );
+                                boost::scoped_array<sal_Int8> pBuf(new sal_Int8[ nCurRecSize ]);
+                                sal_uInt32 nCount = pWMF->Read( pBuf.get(), nCurRecSize );
                                 if( nCount == nCurRecSize )
-                                    pEMFStream->Write( pBuf, nCount );
-                                delete[] pBuf;
+                                    pEMFStream->Write( pBuf.get(), nCount );
                             }
                         }
                     }
diff --git a/vcl/source/filter/wmf/wmfwr.cxx b/vcl/source/filter/wmf/wmfwr.cxx
index 16da0bc..62bf6ec 100644
--- a/vcl/source/filter/wmf/wmfwr.cxx
+++ b/vcl/source/filter/wmf/wmfwr.cxx
@@ -34,6 +34,7 @@
 #include <vcl/metric.hxx>
 #include <basegfx/polygon/b2dpolygon.hxx>
 #include <basegfx/polygon/b2dpolypolygon.hxx>
+#include <boost/scoped_array.hpp>
 
 // MS Windows defines
 
@@ -545,7 +546,7 @@ void WMFWriter::TrueExtTextOut( const Point & rPoint, const OUString & rString,
         pWMF->WriteUChar( (sal_uInt8)0 );
 
     sal_Int32 nOriginalTextLen = rString.getLength();
-    sal_Int16* pConvertedDXAry = new sal_Int16[ nOriginalTextLen ];
+    boost::scoped_array<sal_Int16> pConvertedDXAry(new sal_Int16[ nOriginalTextLen ]);
     sal_Int32 j = 0;
     pConvertedDXAry[ j++ ] = (sal_Int16)ScaleWidth( pDXAry[ 0 ] );
     for (sal_uInt16 i = 1; i < ( nOriginalTextLen - 1 ); ++i)
@@ -565,7 +566,7 @@ void WMFWriter::TrueExtTextOut( const Point & rPoint, const OUString & rString,
                 pWMF->WriteUInt16( (sal_uInt16)0 );
         }
     }
-    delete[] pConvertedDXAry;
+    pConvertedDXAry.reset();
     UpdateRecordHeader();
 }
 
@@ -1198,17 +1199,16 @@ void WMFWriter::WriteRecords( const GDIMetaFile & rMTF )
 
                     pVirDev->SetFont( aSrcFont );
                     nLen = aTemp.getLength();
-                    sal_Int32* pDXAry = nLen ? new sal_Int32[ nLen ] : NULL;
-                    nNormSize = pVirDev->GetTextArray( aTemp, pDXAry );
+                    boost::scoped_array<sal_Int32> pDXAry(nLen ? new sal_Int32[ nLen ] : NULL);
+                    nNormSize = pVirDev->GetTextArray( aTemp, pDXAry.get() );
                     for ( i = 0; i < ( nLen - 1 ); i++ )
                         pDXAry[ i ] = pDXAry[ i ] * (sal_Int32)pA->GetWidth() / nNormSize;
                     if ( ( nLen <= 1 ) || ( (sal_Int32)pA->GetWidth() == nNormSize ) )
-                        delete[] pDXAry, pDXAry = NULL;
+                        pDXAry.reset();
                     aSrcLineInfo = LineInfo();
                     SetAllAttr();
-                    if ( !WMFRecord_Escape_Unicode( pA->GetPoint(), aTemp, pDXAry ) )
-                        WMFRecord_ExtTextOut( pA->GetPoint(), aTemp, pDXAry );
-                    delete[] pDXAry;
+                    if ( !WMFRecord_Escape_Unicode( pA->GetPoint(), aTemp, pDXAry.get() ) )
+                        WMFRecord_ExtTextOut( pA->GetPoint(), aTemp, pDXAry.get() );
                 }
                 break;
 


More information about the Libreoffice-commits mailing list