From 2d1d4638989332f027e902655f56a16e5eefa454 Mon Sep 17 00:00:00 2001
From: Sean McBride <sean@rogue-research.com>
Date: Mon, 29 May 2017 22:53:18 -0400
Subject: [PATCH] Removed unneeded checks for null before using delete
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Found by clang-tidy’s readability-delete-null-pointer
---
 Filters/Core/vtkUnstructuredGridQuadricDecimation.cxx |  5 +----
 .../FlowPaths/vtkLagrangianBasicIntegrationModel.cxx  |  6 +-----
 Filters/Hybrid/vtkPolyDataSilhouette.cxx              |  2 +-
 Filters/Points/vtkPointCloudFilter.cxx                | 11 +++--------
 IO/Geometry/vtkPTSReader.cxx                          |  5 +----
 IO/Image/vtkMRCReader.cxx                             |  5 +----
 Infovis/Core/vtkContinuousScatterplot.cxx             | 10 ++--------
 Rendering/Core/vtkRenderWindow.cxx                    |  5 +----
 Rendering/OpenGL2/vtkOpenGLPointGaussianMapper.cxx    | 10 ++--------
 9 files changed, 13 insertions(+), 46 deletions(-)

diff --git a/Filters/Core/vtkUnstructuredGridQuadricDecimation.cxx b/Filters/Core/vtkUnstructuredGridQuadricDecimation.cxx
index b502bf178b..40ef220702 100644
--- a/Filters/Core/vtkUnstructuredGridQuadricDecimation.cxx
+++ b/Filters/Core/vtkUnstructuredGridQuadricDecimation.cxx
@@ -1627,10 +1627,7 @@ vtkUnstructuredGridQuadricDecimation::vtkUnstructuredGridQuadricDecimation()
 
 vtkUnstructuredGridQuadricDecimation::~vtkUnstructuredGridQuadricDecimation()
 {
-  if (this->ScalarsName)
-  {
-    delete [] this->ScalarsName;
-  }
+  delete [] this->ScalarsName;
 }
 
 void vtkUnstructuredGridQuadricDecimation::ReportError(int err)
diff --git a/Filters/FlowPaths/vtkLagrangianBasicIntegrationModel.cxx b/Filters/FlowPaths/vtkLagrangianBasicIntegrationModel.cxx
index 04cf9bc097..5668cee4b5 100644
--- a/Filters/FlowPaths/vtkLagrangianBasicIntegrationModel.cxx
+++ b/Filters/FlowPaths/vtkLagrangianBasicIntegrationModel.cxx
@@ -555,11 +555,7 @@ vtkLagrangianBasicIntegrationModel::~vtkLagrangianBasicIntegrationModel()
   delete this->DataSets;
   delete this->Surfaces;
   delete this->SurfaceLocators;
-
-  if (this->TmpParticle != NULL)
-  {
-    delete this->TmpParticle;
-  }
+  delete this->TmpParticle;
 
   if (this->TmpArray != NULL)
   {
diff --git a/Filters/Hybrid/vtkPolyDataSilhouette.cxx b/Filters/Hybrid/vtkPolyDataSilhouette.cxx
index eaf152bf6e..4bfd1db466 100644
--- a/Filters/Hybrid/vtkPolyDataSilhouette.cxx
+++ b/Filters/Hybrid/vtkPolyDataSilhouette.cxx
@@ -242,7 +242,7 @@ int vtkPolyDataSilhouette::RequestData(
       polys += np;
     }
 
-    if( this->PreComp->edgeFlag != 0 ) delete [] this->PreComp->edgeFlag;
+    delete [] this->PreComp->edgeFlag;
     this->PreComp->edgeFlag = new bool[ this->PreComp->edges.size() ];
   }
 
diff --git a/Filters/Points/vtkPointCloudFilter.cxx b/Filters/Points/vtkPointCloudFilter.cxx
index 63fa04668b..bc6a70dcfa 100644
--- a/Filters/Points/vtkPointCloudFilter.cxx
+++ b/Filters/Points/vtkPointCloudFilter.cxx
@@ -151,10 +151,7 @@ vtkPointCloudFilter::vtkPointCloudFilter()
 //----------------------------------------------------------------------------
 vtkPointCloudFilter::~vtkPointCloudFilter()
 {
-  if ( this->PointMap )
-  {
-    delete [] this->PointMap;
-  }
+  delete [] this->PointMap;
 }
 
 //----------------------------------------------------------------------------
@@ -193,10 +190,8 @@ int vtkPointCloudFilter::RequestData(
 
   // Reset the filter
   this->NumberOfPointsRemoved = 0;
-  if ( this->PointMap )
-  {
-    delete [] this->PointMap; //might have executed previously
-  }
+
+  delete [] this->PointMap; //might have executed previously
 
   // Check input
   if ( !input || !output )
diff --git a/IO/Geometry/vtkPTSReader.cxx b/IO/Geometry/vtkPTSReader.cxx
index 7a39805a9c..70a6eb9d57 100644
--- a/IO/Geometry/vtkPTSReader.cxx
+++ b/IO/Geometry/vtkPTSReader.cxx
@@ -67,10 +67,7 @@ void vtkPTSReader::SetFileName(const char *filename)
   {
     return;
   }
-  if (this->FileName)
-  {
-    delete [] this->FileName;
-  }
+  delete [] this->FileName;
   if (filename)
   {
     size_t n = strlen(filename) + 1;
diff --git a/IO/Image/vtkMRCReader.cxx b/IO/Image/vtkMRCReader.cxx
index 82dd9af453..d345fe5759 100644
--- a/IO/Image/vtkMRCReader.cxx
+++ b/IO/Image/vtkMRCReader.cxx
@@ -139,10 +139,7 @@ public:
 
   void openFile(const char* file)
   {
-    if (stream != NULL)
-    {
-      delete stream;
-    }
+    delete stream;
     stream = new std::ifstream(file, std::ifstream::binary);
   }
 };
diff --git a/Infovis/Core/vtkContinuousScatterplot.cxx b/Infovis/Core/vtkContinuousScatterplot.cxx
index e361742400..955379c631 100644
--- a/Infovis/Core/vtkContinuousScatterplot.cxx
+++ b/Infovis/Core/vtkContinuousScatterplot.cxx
@@ -488,14 +488,8 @@ int vtkContinuousScatterplot::RequestData(
         for (double threshold = initThreshold; threshold < maxCell; threshold += fragWidth[fieldNr])
         {
           // Initialise framgent face structure for the current cutting plane.
-          if (fragment)
-          {
-            delete fragment;
-          }
-          if (residual)
-          {
-            delete residual;
-          }
+          delete fragment;
+          delete residual;
           fragment = new std::vector<vtkSmartPointer<vtkIdList> >();
           residual = new std::vector<vtkSmartPointer<vtkIdList> >();
 
diff --git a/Rendering/Core/vtkRenderWindow.cxx b/Rendering/Core/vtkRenderWindow.cxx
index 5d6b30281c..4d597b9a08 100644
--- a/Rendering/Core/vtkRenderWindow.cxx
+++ b/Rendering/Core/vtkRenderWindow.cxx
@@ -384,10 +384,7 @@ void vtkRenderWindow::Render()
           *p1 += *p2; p1++; p2++;
         }
       }
-      if (p3)
-      {
-        delete [] p3;
-      }
+      delete [] p3;
     }
 
     // if this is the last sub frame then convert back into unsigned char
diff --git a/Rendering/OpenGL2/vtkOpenGLPointGaussianMapper.cxx b/Rendering/OpenGL2/vtkOpenGLPointGaussianMapper.cxx
index 22808124d3..29cf392db4 100644
--- a/Rendering/OpenGL2/vtkOpenGLPointGaussianMapper.cxx
+++ b/Rendering/OpenGL2/vtkOpenGLPointGaussianMapper.cxx
@@ -576,10 +576,7 @@ void vtkOpenGLPointGaussianMapperHelper::BuildOpacityTable()
   vtkPiecewiseFunction *pwf = this->Owner->GetScalarOpacityFunction();
   int tableSize = this->Owner->GetOpacityTableSize();
 
-  if (this->OpacityTable)
-  {
-    delete [] this->OpacityTable;
-  }
+  delete [] this->OpacityTable;
   this->OpacityTable = new float [tableSize+1];
   if (pwf)
   {
@@ -603,10 +600,7 @@ void vtkOpenGLPointGaussianMapperHelper::BuildScaleTable()
   vtkPiecewiseFunction *pwf = this->Owner->GetScaleFunction();
   int tableSize = this->Owner->GetScaleTableSize();
 
-  if (this->ScaleTable)
-  {
-    delete [] this->ScaleTable;
-  }
+  delete [] this->ScaleTable;
   this->ScaleTable = new float [tableSize+1];
   if (pwf)
   {
-- 
GitLab