Commit 890a9760 authored by Sean McBride's avatar Sean McBride
Browse files

Conservative elimination of !null checks before 'delete'

C++ guarantees that delete 0 and delete [] 0 do nothing.
Older buggy compilers that didn't honour this are no longer
supported by VTK.  Conservatively removed many "if (!ptr)"
checks before using delete in /Common.

Change-Id: Idf185d675e516e7fb5a8a745fd3dbf9720035325
parent a00da5eb
......@@ -101,10 +101,7 @@ void vtkCardinalSpline::Compute ()
// copy the independent variables. Note that if the spline
// is closed the first and last point are assumed repeated -
// so we add and extra point
if (this->Intervals)
{
delete [] this->Intervals;
}
delete [] this->Intervals;
if ( !this->Closed )
{
......@@ -119,10 +116,7 @@ void vtkCardinalSpline::Compute ()
work = new double[size];
// allocate memory for coefficients
if (this->Coefficients)
{
delete [] this->Coefficients;
}
delete [] this->Coefficients;
this->Coefficients = new double [4*size];
// allocate memory for dependent variables
......@@ -166,10 +160,7 @@ void vtkCardinalSpline::Compute ()
work = new double[size];
// allocate memory for coefficients
if (this->Coefficients)
{
delete [] this->Coefficients;
}
delete [] this->Coefficients;
this->Coefficients = new double [4*size];
// allocate memory for dependent variables
......
......@@ -105,10 +105,7 @@ void vtkKochanekSpline::Compute ()
if ( !this->Closed )
{
// copy the independent variables
if (this->Intervals)
{
delete [] this->Intervals;
}
delete [] this->Intervals;
this->Intervals = new double[size];
ts = this->PiecewiseFunction->GetDataPointer ();
for (i = 0; i < size; i++)
......@@ -117,10 +114,7 @@ void vtkKochanekSpline::Compute ()
}
// allocate memory for coefficients
if (this->Coefficients)
{
delete [] this->Coefficients;
}
delete [] this->Coefficients;
this->Coefficients = new double [4*size];
// allocate memory for dependent variables
......@@ -140,10 +134,7 @@ void vtkKochanekSpline::Compute ()
{
size = size + 1;
// copy the independent variables
if (this->Intervals)
{
delete [] this->Intervals;
}
delete [] this->Intervals;
this->Intervals = new double[size];
ts = this->PiecewiseFunction->GetDataPointer ();
for (i = 0; i < size-1; i++)
......@@ -160,10 +151,7 @@ void vtkKochanekSpline::Compute ()
}
// allocate memory for coefficients
if (this->Coefficients)
{
delete [] this->Coefficients;
}
delete [] this->Coefficients;
this->Coefficients = new double [4 * size];
// allocate memory for dependent variables
......
......@@ -67,10 +67,7 @@ vtkBitArray::~vtkBitArray()
delete [] this->Array;
}
delete [] this->Tuple;
if (this->Lookup)
{
delete this->Lookup;
}
delete this->Lookup;
}
//----------------------------------------------------------------------------
......
......@@ -31,10 +31,7 @@ vtkBitArrayIterator::vtkBitArrayIterator()
vtkBitArrayIterator::~vtkBitArrayIterator()
{
this->SetArray(0);
if (this->Tuple)
{
delete [] this->Tuple;
}
delete [] this->Tuple;
}
//-----------------------------------------------------------------------------
......
......@@ -79,10 +79,7 @@ public:
~vtkDebugLeaksHashNode()
{
delete [] this->Key;
if(this->Next)
{
delete this->Next;
}
delete this->Next;
}
public:
vtkDebugLeaksHashNode *Next;
......
......@@ -26,19 +26,13 @@ vtkIdList::vtkIdList()
vtkIdList::~vtkIdList()
{
if ( this->Ids != NULL )
{
delete [] this->Ids;
}
delete [] this->Ids;
}
void vtkIdList::Initialize()
{
if ( this->Ids != NULL )
{
delete [] this->Ids;
this->Ids = NULL;
}
delete [] this->Ids;
this->Ids = NULL;
this->NumberOfIds = 0;
this->Size = 0;
}
......
......@@ -38,10 +38,7 @@ void vtkPriorityQueue::Allocate(const vtkIdType sz, const vtkIdType ext)
}
this->Size = ( sz > 0 ? sz : 1);
if ( this->Array != NULL )
{
delete [] this->Array;
}
delete [] this->Array;
this->Array = new vtkPriorityQueue::Item[sz];
this->Extend = ( ext > 0 ? ext : 1);
this->MaxId = -1;
......@@ -51,10 +48,7 @@ void vtkPriorityQueue::Allocate(const vtkIdType sz, const vtkIdType ext)
vtkPriorityQueue::~vtkPriorityQueue()
{
this->ItemLocation->Delete();
if ( this->Array )
{
delete [] this->Array;
}
delete [] this->Array;
}
// Insert id with priority specified.
......
......@@ -1323,10 +1323,7 @@ void vtkScalarsToColors::MapColorsToColors(
}
}
if (newPtr)
{
delete [] newPtr;
}
delete [] newPtr;
}
//----------------------------------------------------------------------------
......@@ -1383,10 +1380,7 @@ void vtkScalarsToColors::MapVectorsToMagnitude(
numberOfTuples, vectorSize, inInc));
}
if (newPtr)
{
delete [] newPtr;
}
delete [] newPtr;
}
//----------------------------------------------------------------------------
......@@ -1496,10 +1490,7 @@ void vtkScalarsToColors::MapScalarsThroughTable2(
}
}
if (newPtr)
{
delete [] newPtr;
}
delete [] newPtr;
}
//----------------------------------------------------------------------------
......
......@@ -96,7 +96,7 @@ virtual void Set##name (const char* _arg) \
vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << (_arg?_arg:"(null)") ); \
if ( this->name == NULL && _arg == NULL) { return;} \
if ( this->name && _arg && (!strcmp(this->name,_arg))) { return;} \
if (this->name) { delete [] this->name; } \
delete [] this->name; \
if (_arg) \
{ \
size_t n = strlen(_arg) + 1; \
......
......@@ -94,10 +94,7 @@ vtkStringArray::~vtkStringArray()
{
delete [] this->Array;
}
if (this->Lookup)
{
delete this->Lookup;
}
delete this->Lookup;
}
//-----------------------------------------------------------------------------
......
......@@ -107,10 +107,7 @@ vtkVariantArray::~vtkVariantArray()
{
delete [] this->Array;
}
if (this->Lookup)
{
delete this->Lookup;
}
delete this->Lookup;
}
//
......
......@@ -27,10 +27,7 @@ vtkVoidArray::vtkVoidArray()
vtkVoidArray::~vtkVoidArray()
{
if (this->Array)
{
delete [] this->Array;
}
delete [] this->Array;
}
// Allocate memory for this array. Delete old storage only if necessary.
......@@ -55,11 +52,8 @@ int vtkVoidArray::Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext))
// Release storage and reset array to initial state.
void vtkVoidArray::Initialize()
{
if ( this->Array != NULL )
{
delete [] this->Array;
this->Array = NULL;
}
delete [] this->Array;
this->Array = NULL;
this->Size = 0;
this->NumberOfPointers = 0;
}
......
......@@ -351,10 +351,7 @@ int TestAMRBoxSerialization()
rc++;
}
if( buffer != NULL )
{
delete [] buffer;
}
delete [] buffer;
return( rc );
}
......
......@@ -58,11 +58,8 @@ bool vtkAbstractCellLocator::StoreCellBounds()
//----------------------------------------------------------------------------
void vtkAbstractCellLocator::FreeCellBounds()
{
if (this->CellBounds)
{
delete [] this->CellBounds;
this->CellBounds = NULL;
}
delete [] this->CellBounds;
this->CellBounds = NULL;
}
//----------------------------------------------------------------------------
int vtkAbstractCellLocator::IntersectWithLine(
......
......@@ -71,41 +71,26 @@ void vtkBSPCuts::Initialize()
//----------------------------------------------------------------------------
void vtkBSPCuts::ResetArrays()
{
if (this->Dim)
{
delete [] this->Dim;
this->Dim = NULL;
}
if (this->Coord)
{
delete [] this->Coord;
this->Coord = NULL;
}
if (this->Lower)
{
delete [] this->Lower;
this->Lower = NULL;
}
if (this->Upper)
{
delete [] this->Upper;
this->Upper = NULL;
}
if (this->LowerDataCoord)
{
delete [] this->LowerDataCoord;
this->LowerDataCoord = NULL;
}
if (this->UpperDataCoord)
{
delete [] this->UpperDataCoord;
this->UpperDataCoord = NULL;
}
if (this->Npoints)
{
delete [] this->Npoints;
this->Npoints = NULL;
}
delete [] this->Dim;
this->Dim = NULL;
delete [] this->Coord;
this->Coord = NULL;
delete [] this->Lower;
this->Lower = NULL;
delete [] this->Upper;
this->Upper = NULL;
delete [] this->LowerDataCoord;
this->LowerDataCoord = NULL;
delete [] this->UpperDataCoord;
this->UpperDataCoord = NULL;
delete [] this->Npoints;
this->Npoints = NULL;
this->NumberOfCuts = 0;
}
......
......@@ -86,10 +86,7 @@ vtkBSPIntersections::vtkBSPIntersections()
vtkBSPIntersections::~vtkBSPIntersections()
{
this->SetCuts(NULL);
if (this->RegionList)
{
delete [] this->RegionList;
}
delete [] this->RegionList;
}
//----------------------------------------------------------------------------
int vtkBSPIntersections::BuildRegionList()
......@@ -100,11 +97,8 @@ int vtkBSPIntersections::BuildRegionList()
return 0;
}
if (this->RegionList)
{
delete [] this->RegionList;
this->RegionList = NULL;
}
delete [] this->RegionList;
this->RegionList = NULL;
vtkKdNode *top = NULL;
if (this->Cuts)
......
......@@ -28,10 +28,7 @@ void vtkCellLinks::Allocate(vtkIdType sz, vtkIdType ext)
static vtkCellLinks::Link linkInit = {0,NULL};
this->Size = sz;
if ( this->Array != NULL )
{
delete [] this->Array;
}
delete [] this->Array;
this->Array = new vtkCellLinks::Link[sz];
this->Extend = ext;
this->MaxId = -1;
......@@ -52,10 +49,7 @@ vtkCellLinks::~vtkCellLinks()
for (vtkIdType i=0; i<=this->MaxId; i++)
{
if ( this->Array[i].cells != NULL )
{
delete [] this->Array[i].cells;
}
delete [] this->Array[i].cells;
}
delete [] this->Array;
......
......@@ -83,20 +83,14 @@ vtkCellLocator::vtkCellLocator()
//----------------------------------------------------------------------------
vtkCellLocator::~vtkCellLocator()
{
if (this->Buckets)
{
delete this->Buckets;
this->Buckets = NULL;
}
delete this->Buckets;
this->Buckets = NULL;
this->FreeSearchStructure();
this->FreeCellBounds();
if (this->CellHasBeenVisited)
{
delete [] this->CellHasBeenVisited;
this->CellHasBeenVisited = NULL;
}
delete [] this->CellHasBeenVisited;
this->CellHasBeenVisited = NULL;
}
//----------------------------------------------------------------------------
......@@ -1229,11 +1223,8 @@ void vtkCellLocator::BuildLocatorInternal()
{
this->FreeSearchStructure();
}
if ( this->CellHasBeenVisited )
{
delete [] this->CellHasBeenVisited;
this->CellHasBeenVisited = NULL;
}
delete [] this->CellHasBeenVisited;
this->CellHasBeenVisited = NULL;
this->FreeCellBounds();
// Size the root cell. Initialize cell data structure, compute
......
......@@ -2070,11 +2070,8 @@ void vtkDataSetAttributes::FieldList::SetField(
vtkAbstractArray *aa)
{
// Store the field name
if ( this->Fields[index] )
{
delete [] this->Fields[index];
this->Fields[index] = 0;
}
delete [] this->Fields[index];
this->Fields[index] = 0;
const char* name=aa->GetName();
if (name)
{
......
......@@ -529,10 +529,7 @@ vtkIdList **vtkEdgeTable::Resize(vtkIdType sz)
{
newAttributeArray[i] = NULL;
}
if ( this->Attributes )
{
delete [] this->Attributes;
}
delete [] this->Attributes;
this->Attributes = newAttributeArray;
}
else if ( this->StoreAttributes == 2 )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment