[Libreoffice-commits] core.git: avmedia/source basic/source bridges/source configmgr/source sfx2/source shell/source vcl/win xmlsecurity/source

Stephan Bergmann sbergman at redhat.com
Thu Feb 2 14:18:33 UTC 2017


 avmedia/source/win/framegrabber.cxx                            |   12 +++---
 basic/source/runtime/methods.cxx                               |    3 -
 bridges/source/cpp_uno/msvc_win32_x86-64/except.cxx            |    8 ++--
 configmgr/source/winreg.cxx                                    |   18 +++++-----
 sfx2/source/doc/graphhelp.cxx                                  |   12 ++----
 shell/source/win32/shlxthandler/propsheets/propsheets.cxx      |    8 ++--
 vcl/win/gdi/salprn.cxx                                         |   10 +++--
 vcl/win/window/salframe.cxx                                    |    8 ++--
 xmlsecurity/source/xmlsec/mscrypt/sanextension_mscryptimpl.cxx |    9 ++---
 9 files changed, 46 insertions(+), 42 deletions(-)

New commits:
commit 5595ee701eab0fef0683c93e3c99788ab1b08520
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Feb 2 15:17:52 2017 +0100

    loplugin:useuniqueptr
    
    Change-Id: I3a246a22baaac8195dc1b94c42994de7d80e8336

diff --git a/avmedia/source/win/framegrabber.cxx b/avmedia/source/win/framegrabber.cxx
index 3d1f590..ce24b96 100644
--- a/avmedia/source/win/framegrabber.cxx
+++ b/avmedia/source/win/framegrabber.cxx
@@ -17,6 +17,10 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <sal/config.h>
+
+#include <memory>
+
 #if defined _MSC_VER
 #pragma warning(push, 1)
 #pragma warning(disable: 4917)
@@ -170,13 +174,13 @@ uno::Reference< graphic::XGraphic > SAL_CALL FrameGrabber::grabFrame( double fMe
                 SUCCEEDED( pDet->GetBitmapBits( 0, &nSize, nullptr, nWidth, nHeight ) ) &&
                 ( nSize > 0  ) )
             {
-                char* pBuffer = new char[ nSize ];
+                auto pBuffer = std::unique_ptr<char[]>(new char[ nSize ]);
 
                 try
                 {
-                    if( SUCCEEDED( pDet->GetBitmapBits( fMediaTime, nullptr, pBuffer, nWidth, nHeight ) ) )
+                    if( SUCCEEDED( pDet->GetBitmapBits( fMediaTime, nullptr, pBuffer.get(), nWidth, nHeight ) ) )
                     {
-                        SvMemoryStream  aMemStm( pBuffer, nSize, StreamMode::READ | StreamMode::WRITE );
+                        SvMemoryStream  aMemStm( pBuffer.get(), nSize, StreamMode::READ | StreamMode::WRITE );
                         Bitmap          aBmp;
 
                         if( ReadDIB(aBmp, aMemStm, false ) && !aBmp.IsEmpty() )
@@ -189,8 +193,6 @@ uno::Reference< graphic::XGraphic > SAL_CALL FrameGrabber::grabFrame( double fMe
                 catch( ... )
                 {
                 }
-
-                delete [] pBuffer;
             }
         }
 
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index 1a4c12b..3447bff 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -419,7 +419,7 @@ RTLFUNC(CurDir)
             }
         }
     }
-    char* pBuffer = new char[ _MAX_PATH ];
+    char pBuffer[ _MAX_PATH ];
     if ( _getdcwd( nCurDir, pBuffer, _MAX_PATH ) != nullptr )
     {
         rPar.Get(0)->PutString( OUString::createFromAscii( pBuffer ) );
@@ -428,7 +428,6 @@ RTLFUNC(CurDir)
     {
         StarBASIC::Error( ERRCODE_BASIC_NO_DEVICE );
     }
-    delete [] pBuffer;
 
 #else
 
diff --git a/bridges/source/cpp_uno/msvc_win32_x86-64/except.cxx b/bridges/source/cpp_uno/msvc_win32_x86-64/except.cxx
index 15a12d5..180828b 100644
--- a/bridges/source/cpp_uno/msvc_win32_x86-64/except.cxx
+++ b/bridges/source/cpp_uno/msvc_win32_x86-64/except.cxx
@@ -236,6 +236,9 @@ void
 
 #pragma warning( disable : 4237 )
 #include <sal/config.h>
+
+#include <memory>
+
 #include <malloc.h>
 #include <new.h>
 #include <typeinfo.h>
@@ -617,7 +620,7 @@ RaiseInfo::RaiseInfo(typelib_TypeDescription * pTD)throw ()
     // 2.Pass: Get the total needed memory for class ExceptionType
     // (with embedded type_info) and keep the sizes for each instance
     // is stored in allocated int array
-    int *exceptionTypeSizeArray = new int[nLen];
+    auto exceptionTypeSizeArray = std::unique_ptr<int[]>(new int[nLen]);
 
     nLen = 0;
     for (pCompTD = reinterpret_cast<typelib_CompoundTypeDescription*>(pTD);
@@ -697,9 +700,6 @@ RaiseInfo::RaiseInfo(typelib_TypeDescription * pTD)throw ()
     }
     // Final check: end of address calculation must be end of mem
     assert(etMem + etMemOffset == pCode + totalSize);
-
-    // remove array
-    delete[] exceptionTypeSizeArray;
 }
 
 #if !defined LEAK_STATIC_DATA
diff --git a/configmgr/source/winreg.cxx b/configmgr/source/winreg.cxx
index c2e709b..60f99f1 100644
--- a/configmgr/source/winreg.cxx
+++ b/configmgr/source/winreg.cxx
@@ -9,6 +9,8 @@
  */
 
 #include <cwchar>
+#include <memory>
+
 #ifdef _MSC_VER
 #pragma warning(push, 1) /* disable warnings within system headers */
 #endif
@@ -103,8 +105,10 @@ void dumpWindowsRegistryKey(HKEY hKey, OUString const & aKeyName, TempFile &aFil
         else if(nValues)
         {
             // No more subkeys, we are at a leaf
-            wchar_t* pValueName = new wchar_t[nLongestValueNameLen + 1];
-            wchar_t* pValue = new wchar_t[nLongestValueLen + 1];
+            auto pValueName = std::unique_ptr<wchar_t[]>(
+                new wchar_t[nLongestValueNameLen + 1]);
+            auto pValue = std::unique_ptr<wchar_t[]>(
+                new wchar_t[nLongestValueLen + 1]);
 
             bool bFinal = false;
             OUString aValue;
@@ -114,13 +118,13 @@ void dumpWindowsRegistryKey(HKEY hKey, OUString const & aKeyName, TempFile &aFil
                 DWORD nValueNameLen = nLongestValueNameLen + 1;
                 DWORD nValueLen = nLongestValueLen + 1;
 
-                RegEnumValueW(hCurKey, i, pValueName, &nValueNameLen, nullptr, nullptr, reinterpret_cast<LPBYTE>(pValue), &nValueLen);
+                RegEnumValueW(hCurKey, i, pValueName.get(), &nValueNameLen, nullptr, nullptr, reinterpret_cast<LPBYTE>(pValue.get()), &nValueLen);
                 const wchar_t wsValue[] = L"Value";
                 const wchar_t wsFinal[] = L"Final";
 
-                if(!wcscmp(pValueName, wsValue))
-                    aValue = OUString(pValue);
-                if(!wcscmp(pValueName, wsFinal) && *reinterpret_cast<DWORD*>(pValue) == 1)
+                if(!wcscmp(pValueName.get(), wsValue))
+                    aValue = OUString(pValue.get());
+                if(!wcscmp(pValueName.get(), wsFinal) && *reinterpret_cast<DWORD*>(pValue.get()) == 1)
                     bFinal = true;
             }
             sal_Int32 aLastSeparator = aKeyName.lastIndexOf('\\');
@@ -177,8 +181,6 @@ void dumpWindowsRegistryKey(HKEY hKey, OUString const & aKeyName, TempFile &aFil
             for(; nCloseNode > 0; nCloseNode--)
                 writeData(aFileHandle, "</node>");
             writeData(aFileHandle, "</item>\n");
-            delete[] pValueName;
-            delete[] pValue;
         }
         RegCloseKey(hCurKey);
     }
diff --git a/sfx2/source/doc/graphhelp.cxx b/sfx2/source/doc/graphhelp.cxx
index 542c8ff..f6ab18c 100644
--- a/sfx2/source/doc/graphhelp.cxx
+++ b/sfx2/source/doc/graphhelp.cxx
@@ -118,17 +118,17 @@ void* GraphicHelper::getWinMetaFileFromGDI_Impl( const GDIMetaFile* pGDIMeta, co
 #ifdef _WIN32
     if ( pGDIMeta )
     {
-        SvMemoryStream* pStream = new SvMemoryStream( 65535, 65535 );
+        SvMemoryStream pStream( 65535, 65535 );
         Graphic aGraph( *pGDIMeta );
-        bool bFailed = GraphicConverter::Export( *pStream, aGraph, ConvertDataFormat::WMF );
-        pStream->Flush();
+        bool bFailed = GraphicConverter::Export( pStream, aGraph, ConvertDataFormat::WMF );
+        pStream.Flush();
         if ( !bFailed )
         {
-            sal_Int32 nLength = pStream->Seek( STREAM_SEEK_TO_END );
+            sal_Int32 nLength = pStream.Seek( STREAM_SEEK_TO_END );
             if ( nLength > 22 )
             {
                 HMETAFILE hMeta = SetMetaFileBitsEx( nLength - 22,
-                                ( static_cast< const unsigned char*>( pStream->GetData() ) ) + 22 );
+                                ( static_cast< const unsigned char*>( pStream.GetData() ) ) + 22 );
 
                 if ( hMeta )
                 {
@@ -166,8 +166,6 @@ void* GraphicHelper::getWinMetaFileFromGDI_Impl( const GDIMetaFile* pGDIMeta, co
                 }
             }
         }
-
-        delete pStream;
     }
 #endif
 
diff --git a/shell/source/win32/shlxthandler/propsheets/propsheets.cxx b/shell/source/win32/shlxthandler/propsheets/propsheets.cxx
index 9d524e9..1ac28c3 100644
--- a/shell/source/win32/shlxthandler/propsheets/propsheets.cxx
+++ b/shell/source/win32/shlxthandler/propsheets/propsheets.cxx
@@ -36,6 +36,7 @@
 #pragma warning(pop)
 #endif
 
+#include <memory>
 #include <string>
 #include <vector>
 #include <utility>
@@ -139,12 +140,12 @@ HRESULT STDMETHODCALLTYPE CPropertySheet::Initialize(
         UINT size = DragQueryFileW( static_cast<HDROP>(medium.hGlobal), 0, nullptr, 0 );
         if ( size != 0 )
         {
-            WCHAR * buffer = new WCHAR[ size + 1 ];
+            auto buffer = std::unique_ptr<WCHAR[]>(new WCHAR[ size + 1 ]);
             UINT result_size = DragQueryFileW( static_cast<HDROP>(medium.hGlobal),
-                                               0, buffer, size + 1 );
+                                               0, buffer.get(), size + 1 );
             if ( result_size != 0 )
             {
-                std::wstring fname = getShortPathName( buffer );
+                std::wstring fname = getShortPathName( buffer.get() );
                 std::string fnameA = WStringToString( fname );
                 ZeroMemory( m_szFileName, sizeof( m_szFileName ) );
                 strncpy( m_szFileName, fnameA.c_str(), ( sizeof( m_szFileName ) - 1 ) );
@@ -152,7 +153,6 @@ HRESULT STDMETHODCALLTYPE CPropertySheet::Initialize(
             }
             else
                 hr = E_INVALIDARG;
-            delete [] buffer;
         }
         else
             hr = E_INVALIDARG;
diff --git a/vcl/win/gdi/salprn.cxx b/vcl/win/gdi/salprn.cxx
index db54dd0..60b5320 100644
--- a/vcl/win/gdi/salprn.cxx
+++ b/vcl/win/gdi/salprn.cxx
@@ -17,6 +17,9 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <sal/config.h>
+
+#include <memory>
 #include <string.h>
 
 #include <svsys.h>
@@ -1220,11 +1223,10 @@ OUString WinSalInfoPrinter::GetPaperBinName( const ImplJobSetup* pSetupData, sal
     DWORD nBins = ImplDeviceCaps( this, DC_BINNAMES, nullptr, pSetupData );
     if ( (nPaperBin < nBins) && (nBins != GDI_ERROR) )
     {
-        sal_Unicode* pBuffer = new sal_Unicode[nBins*24];
-        DWORD nRet = ImplDeviceCaps( this, DC_BINNAMES, reinterpret_cast<BYTE*>(pBuffer), pSetupData );
+        auto pBuffer = std::unique_ptr<sal_Unicode[]>(new sal_Unicode[nBins*24]);
+        DWORD nRet = ImplDeviceCaps( this, DC_BINNAMES, reinterpret_cast<BYTE*>(pBuffer.get()), pSetupData );
         if ( nRet && (nRet != GDI_ERROR) )
-            aPaperBinName = OUString( pBuffer + (nPaperBin*24) );
-        delete [] pBuffer;
+            aPaperBinName = OUString( pBuffer.get() + (nPaperBin*24) );
     }
 
     return aPaperBinName;
diff --git a/vcl/win/window/salframe.cxx b/vcl/win/window/salframe.cxx
index 689a69c..d908dbc 100644
--- a/vcl/win/window/salframe.cxx
+++ b/vcl/win/window/salframe.cxx
@@ -26,6 +26,7 @@
 
 #include <officecfg/Office/Common.hxx>
 
+#include <memory>
 #include <string.h>
 #include <limits.h>
 
@@ -5010,10 +5011,9 @@ static bool ImplHandleIMECompositionInput( WinSalFrame* pFrame,
         LONG nTextLen = ImmGetCompositionStringW( hIMC, GCS_RESULTSTR, nullptr, 0 ) / sizeof( WCHAR );
         if ( nTextLen >= 0 )
         {
-            WCHAR* pTextBuf = new WCHAR[nTextLen];
-            ImmGetCompositionStringW( hIMC, GCS_RESULTSTR, pTextBuf, nTextLen*sizeof( WCHAR ) );
-            aEvt.maText = OUString( reinterpret_cast<const sal_Unicode*>(pTextBuf), (sal_Int32)nTextLen );
-            delete [] pTextBuf;
+            auto pTextBuf = std::unique_ptr<WCHAR[]>(new WCHAR[nTextLen]);
+            ImmGetCompositionStringW( hIMC, GCS_RESULTSTR, pTextBuf.get(), nTextLen*sizeof( WCHAR ) );
+            aEvt.maText = OUString( reinterpret_cast<const sal_Unicode*>(pTextBuf.get()), (sal_Int32)nTextLen );
         }
 
         aEvt.mnCursorPos = aEvt.maText.getLength();
diff --git a/xmlsecurity/source/xmlsec/mscrypt/sanextension_mscryptimpl.cxx b/xmlsecurity/source/xmlsec/mscrypt/sanextension_mscryptimpl.cxx
index 5fba1ff..35f3242 100644
--- a/xmlsecurity/source/xmlsec/mscrypt/sanextension_mscryptimpl.cxx
+++ b/xmlsecurity/source/xmlsec/mscrypt/sanextension_mscryptimpl.cxx
@@ -18,6 +18,9 @@
  */
 
 #include <sal/config.h>
+
+#include <memory>
+
 #include <rtl/uuid.h>
 #include <rtl/ustring.hxx>
 #include <com/sun/star/security/ExtAltNameType.hpp>
@@ -65,7 +68,7 @@ css::uno::Sequence< css::security::CertAltNameEntry > SAL_CALL SanExtensionImpl:
         DWORD size;
         CryptDecodeObjectEx(X509_ASN_ENCODING, X509_ALTERNATE_NAME, reinterpret_cast<unsigned char*>(m_xExtnValue.getArray()), m_xExtnValue.getLength(), CRYPT_DECODE_ALLOC_FLAG | CRYPT_DECODE_NOCOPY_FLAG, nullptr,&subjectName, &size);
 
-        CertAltNameEntry* arrCertAltNameEntry = new CertAltNameEntry[subjectName->cAltEntry];
+        auto arrCertAltNameEntry = std::unique_ptr<CertAltNameEntry[]>(new CertAltNameEntry[subjectName->cAltEntry]);
 
         for (unsigned int i = 0; i < (unsigned int)subjectName->cAltEntry; i++){
           PCERT_ALT_NAME_ENTRY pEntry = &subjectName->rgAltEntry[i];
@@ -122,9 +125,7 @@ css::uno::Sequence< css::security::CertAltNameEntry > SAL_CALL SanExtensionImpl:
                 break;
           }
         }
-        m_Entries = ::comphelper::arrayToSequence< css::security::CertAltNameEntry >(arrCertAltNameEntry, subjectName->cAltEntry);
-
-        delete [] arrCertAltNameEntry;
+        m_Entries = ::comphelper::arrayToSequence< css::security::CertAltNameEntry >(arrCertAltNameEntry.get(), subjectName->cAltEntry);
     }
 
     return m_Entries;


More information about the Libreoffice-commits mailing list