From cee2ccb38f0b6d223d9c60da6538f06a84ad6192 Mon Sep 17 00:00:00 2001
From: Noel Grandin <noel.grandin@collabora.co.uk>
Date: Mon, 30 Apr 2018 18:46:04 +0200
Subject: loplugin:useuniqueptr in X11SalBitmap

Change-Id: I3fedb4b25683bafbdb7c761387d47a8b30ef8083
Reviewed-on: https://gerrit.libreoffice.org/53706
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
---
 vcl/inc/unx/salbmp.h           |  2 +-
 vcl/inc/unx/salgdi.h           |  2 +-
 vcl/unx/generic/gdi/salbmp.cxx | 27 +++++++--------------------
 vcl/unx/generic/gdi/salgdi.cxx |  4 ++--
 vcl/unx/generic/gdi/salvd.cxx  | 12 +++++-------
 5 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/vcl/inc/unx/salbmp.h b/vcl/inc/unx/salbmp.h
index 8e1b7d5a6bf6..34c7ff076156 100644
--- a/vcl/inc/unx/salbmp.h
+++ b/vcl/inc/unx/salbmp.h
@@ -71,7 +71,7 @@ public:
 private:
 
     std::unique_ptr<BitmapBuffer> mpDIB;
-    ImplSalDDB*     mpDDB;
+    mutable std::unique_ptr<ImplSalDDB> mpDDB;
     bool            mbGrey;
 
 public:
diff --git a/vcl/inc/unx/salgdi.h b/vcl/inc/unx/salgdi.h
index dded647ab97d..8cfc5abb2add 100644
--- a/vcl/inc/unx/salgdi.h
+++ b/vcl/inc/unx/salgdi.h
@@ -318,7 +318,7 @@ protected:
     SalVirtualDevice*               m_pVDev;  // the SalVirtualDevice which created this Graphics or NULL
 
     const SalColormap*              m_pColormap;
-    SalColormap*                    m_pDeleteColormap;
+    std::unique_ptr<SalColormap>    m_pDeleteColormap;
     Drawable                        hDrawable_;     // use
     SalX11Screen                    m_nXScreen;
     mutable XRenderPictFormat*      m_pXRenderFormat;
diff --git a/vcl/unx/generic/gdi/salbmp.cxx b/vcl/unx/generic/gdi/salbmp.cxx
index 121290a90abc..d50c92feba90 100644
--- a/vcl/unx/generic/gdi/salbmp.cxx
+++ b/vcl/unx/generic/gdi/salbmp.cxx
@@ -94,11 +94,7 @@ void X11SalBitmap::ImplDestroyCache()
 
 void X11SalBitmap::ImplRemovedFromCache()
 {
-    if( mpDDB )
-    {
-        delete mpDDB;
-        mpDDB = nullptr;
-    }
+    mpDDB.reset();
 }
 
 #if defined HAVE_VALGRIND_HEADERS
@@ -590,7 +586,7 @@ bool X11SalBitmap::ImplCreateFromDrawable(
     Destroy();
 
     if( aDrawable && nWidth && nHeight && nDrawableDepth )
-        mpDDB = new ImplSalDDB( aDrawable, nScreen, nDrawableDepth, nX, nY, nWidth, nHeight );
+        mpDDB.reset(new ImplSalDDB( aDrawable, nScreen, nDrawableDepth, nX, nY, nWidth, nHeight ));
 
     return( mpDDB != nullptr );
 }
@@ -618,8 +614,7 @@ ImplSalDDB* X11SalBitmap::ImplGetDDB(
                                                                         mbGrey );
             }
 
-            delete mpDDB;
-            const_cast<X11SalBitmap*>(this)->mpDDB = nullptr;
+            mpDDB.reset();
         }
 
         if( mpCache )
@@ -681,7 +676,7 @@ ImplSalDDB* X11SalBitmap::ImplGetDDB(
 
         if( pImage )
         {
-            const_cast<X11SalBitmap*>(this)->mpDDB = new ImplSalDDB( pImage, aDrawable, nXScreen, aTwoRect );
+            mpDDB.reset(new ImplSalDDB( pImage, aDrawable, nXScreen, aTwoRect ));
             delete[] pImage->data;
             pImage->data = nullptr;
             XDestroyImage( pImage );
@@ -691,7 +686,7 @@ ImplSalDDB* X11SalBitmap::ImplGetDDB(
         }
     }
 
-    return mpDDB;
+    return mpDDB.get();
 }
 
 void X11SalBitmap::ImplDraw(
@@ -809,11 +804,7 @@ void X11SalBitmap::Destroy()
         mpDIB.reset();
     }
 
-    if( mpDDB )
-    {
-        delete mpDDB;
-        mpDDB = nullptr;
-    }
+    mpDDB.reset();
 
     if( mpCache )
         mpCache->ImplRemove( this );
@@ -873,11 +864,7 @@ void X11SalBitmap::ReleaseBuffer( BitmapBuffer*, BitmapAccessMode nMode )
 {
     if( nMode == BitmapAccessMode::Write )
     {
-        if( mpDDB )
-        {
-            delete mpDDB;
-            mpDDB = nullptr;
-        }
+        mpDDB.reset();
 
         if( mpCache )
             mpCache->ImplRemove( this );
diff --git a/vcl/unx/generic/gdi/salgdi.cxx b/vcl/unx/generic/gdi/salgdi.cxx
index 005cbf4be7d6..80dc7ecad17c 100644
--- a/vcl/unx/generic/gdi/salgdi.cxx
+++ b/vcl/unx/generic/gdi/salgdi.cxx
@@ -132,8 +132,8 @@ void X11SalGraphics::freeResources()
     }
     if( m_pDeleteColormap )
     {
-        delete m_pDeleteColormap;
-        m_pColormap = m_pDeleteColormap = nullptr;
+        m_pDeleteColormap.reset();
+        m_pColormap = nullptr;
     }
     if( m_aXRenderPicture )
     {
diff --git a/vcl/unx/generic/gdi/salvd.cxx b/vcl/unx/generic/gdi/salvd.cxx
index 3bbe0fde016b..d7223df9de8b 100644
--- a/vcl/unx/generic/gdi/salvd.cxx
+++ b/vcl/unx/generic/gdi/salvd.cxx
@@ -55,8 +55,6 @@ std::unique_ptr<SalVirtualDevice> X11SalInstance::CreateVirtualDevice(SalGraphic
 void X11SalGraphics::Init( X11SalVirtualDevice *pDevice, SalColormap* pColormap,
                            bool bDeleteColormap )
 {
-    SalColormap *pOrigDeleteColormap = m_pDeleteColormap;
-
     SalDisplay *pDisplay  = pDevice->GetDisplay();
     m_nXScreen = pDevice->GetXScreenNumber();
 
@@ -67,15 +65,15 @@ void X11SalGraphics::Init( X11SalVirtualDevice *pDevice, SalColormap* pColormap,
     {
         m_pColormap = pColormap;
         if( bDeleteColormap )
-            m_pDeleteColormap = pColormap;
+            m_pDeleteColormap.reset(pColormap);
     }
     else if( nDeviceDepth == nVisualDepth )
         m_pColormap = &pDisplay->GetColormap( m_nXScreen );
     else if( nDeviceDepth == 1 )
-        m_pColormap = m_pDeleteColormap = new SalColormap();
-
-    if (m_pDeleteColormap != pOrigDeleteColormap)
-        delete pOrigDeleteColormap;
+    {
+        m_pDeleteColormap.reset(new SalColormap());
+        m_pColormap = m_pDeleteColormap.get();
+    }
 
     m_pVDev      = pDevice;
     m_pFrame     = nullptr;
-- 
cgit