Commit 5678f1cb authored by Sean McBride's avatar Sean McBride
Browse files

Removed many unneeded null checks before delete

Also removed some dead code as a consequence,
like setting the deallocated pointer to null
then to a new address.

Also removed setting some ivars to null in dtors.
parent 565dd9a1
......@@ -61,7 +61,7 @@ vtkBitArray::vtkBitArray()
//----------------------------------------------------------------------------
vtkBitArray::~vtkBitArray()
{
if ((this->Array) && (!this->SaveUserArray))
if (!this->SaveUserArray)
{
delete [] this->Array;
}
......@@ -131,7 +131,7 @@ int vtkBitArray::Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext))
{
if ( sz > this->Size )
{
if (( this->Array != NULL ) && (!this->SaveUserArray))
if (!this->SaveUserArray)
{
delete [] this->Array;
}
......@@ -153,7 +153,7 @@ int vtkBitArray::Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext))
// Release storage and reset array to initial state.
void vtkBitArray::Initialize()
{
if (( this->Array != NULL ) && (!this->SaveUserArray))
if (!this->SaveUserArray)
{
delete [] this->Array;
}
......@@ -191,7 +191,7 @@ void vtkBitArray::DeepCopy(vtkDataArray *ia)
if ( this != ia )
{
if ((this->Array) && (!this->SaveUserArray))
if (!this->SaveUserArray)
{
delete [] this->Array;
}
......
......@@ -32,7 +32,7 @@ vtkOStrStreamWrapper::vtkOStrStreamWrapper()
//----------------------------------------------------------------------------
vtkOStrStreamWrapper::~vtkOStrStreamWrapper()
{
if(this->Result && !this->Frozen)
if(!this->Frozen)
{
delete [] this->Result;
}
......
......@@ -89,7 +89,7 @@ vtkStringArray::vtkStringArray()
vtkStringArray::~vtkStringArray()
{
if ((this->Array) && (!this->SaveUserArray))
if (!this->SaveUserArray)
{
delete [] this->Array;
}
......@@ -141,7 +141,7 @@ int vtkStringArray::Allocate(vtkIdType sz, vtkIdType)
{
if(sz > this->Size)
{
if(this->Array && !this->SaveUserArray)
if(!this->SaveUserArray)
{
delete [] this->Array;
}
......@@ -166,7 +166,7 @@ int vtkStringArray::Allocate(vtkIdType sz, vtkIdType)
void vtkStringArray::Initialize()
{
if(this->Array && !this->SaveUserArray)
if(!this->SaveUserArray)
{
delete [] this->Array;
}
......@@ -211,7 +211,7 @@ void vtkStringArray::DeepCopy(vtkAbstractArray* aa)
}
// Free our previous memory.
if(this->Array && !this->SaveUserArray)
if(!this->SaveUserArray)
{
delete [] this->Array;
}
......
......@@ -102,7 +102,7 @@ vtkVariantArray::vtkVariantArray()
//----------------------------------------------------------------------------
vtkVariantArray::~vtkVariantArray()
{
if ((this->Array) && (!this->SaveUserArray))
if (!this->SaveUserArray)
{
delete [] this->Array;
}
......@@ -120,7 +120,7 @@ int vtkVariantArray::Allocate(vtkIdType sz, vtkIdType)
{
if(sz > this->Size)
{
if(this->Array && !this->SaveUserArray)
if(!this->SaveUserArray)
{
delete [] this->Array;
}
......@@ -143,7 +143,7 @@ int vtkVariantArray::Allocate(vtkIdType sz, vtkIdType)
//----------------------------------------------------------------------------
void vtkVariantArray::Initialize()
{
if(this->Array && !this->SaveUserArray)
if(!this->SaveUserArray)
{
delete [] this->Array;
}
......@@ -443,7 +443,7 @@ void vtkVariantArray::DeepCopy(vtkAbstractArray *aa)
}
// Free our previous memory.
if(this->Array && !this->SaveUserArray)
if(!this->SaveUserArray)
{
delete [] this->Array;
}
......
......@@ -42,7 +42,7 @@ vtkOpenQubeMoleculeSource::vtkOpenQubeMoleculeSource()
vtkOpenQubeMoleculeSource::~vtkOpenQubeMoleculeSource()
{
this->SetFileName(NULL);
if (this->CleanUpBasisSet && this->BasisSet != NULL)
if (this->CleanUpBasisSet)
{
delete this->BasisSet;
this->BasisSet = NULL;
......@@ -68,7 +68,7 @@ void vtkOpenQubeMoleculeSource::SetBasisSet(OpenQube::BasisSet *b)
<< "): setting BasisSet to " << b);
if (this->BasisSet != b)
{
if (this->CleanUpBasisSet && this->BasisSet != NULL)
if (this->CleanUpBasisSet)
{
delete this->BasisSet;
}
......
......@@ -76,8 +76,7 @@ namespace
}
~InitializeFunctor()
{
if ( this->Locks )
delete [] this->Locks;
delete [] this->Locks;
}
void operator()(vtkIdType start, vtkIdType end)
......
......@@ -61,11 +61,8 @@ vtkAbstractInterpolatedVelocityField::~vtkAbstractInterpolatedVelocityField()
this->LastDataSet = 0;
this->SetVectorsSelection(0);
if ( this->Weights )
{
delete[] this->Weights;
this->Weights = 0;
}
delete[] this->Weights;
this->Weights = 0;
if ( this->Cell )
{
......
......@@ -701,11 +701,8 @@ void vtkImageMarchingCubes::InitializeLocator(int min0, int max0,
void vtkImageMarchingCubes::DeleteLocator()
{
// Free old memory
if (this->LocatorPointIds)
{
delete [] this->LocatorPointIds;
this->LocatorPointIds = NULL;
}
delete [] this->LocatorPointIds;
this->LocatorPointIds = NULL;
}
//----------------------------------------------------------------------------
......
......@@ -912,11 +912,7 @@ int vtkMatlabEngineFilter::SetMatlabScriptFromFile(const char* fname)
len = ftell(fp);
fseek(fp,0,SEEK_SET);
if(this->MatlabFileScript)
{
delete [] this->MatlabFileScript;
this->MatlabFileScript = 0;
}
delete [] this->MatlabFileScript;
this->MatlabFileScript = new char[len+1];
fread(this->MatlabFileScript,len,1,fp);
......
......@@ -1955,7 +1955,7 @@ int vtkPKdTree::CompleteTree()
if (this->AllCheckForFailure(fail, "CompleteTree", "memory allocation"))
{
if (buf) delete [] buf;
delete [] buf;
return 1;
}
......
......@@ -965,11 +965,8 @@ void vtkStructuredImplicitConnectivity::RegisterGrid(
(this->InputGrid == NULL) );
assert("pre: input grid ID should be >= 0" && (gridID >= 0) );
if (this->InputGrid)
{
delete this->InputGrid;
this->InputGrid = NULL;
}
delete this->InputGrid;
this->InputGrid = NULL;
// Only add if the grid falls within the output extent. Processes that do
// not contain the VOI will fail this test.
......@@ -996,11 +993,8 @@ void vtkStructuredImplicitConnectivity::RegisterRectilinearGrid(
(this->InputGrid == NULL) );
assert("pre: input grid ID should be >= 0" && (gridID >= 0) );
if (this->InputGrid)
{
delete this->InputGrid;
this->InputGrid = NULL;
}
delete this->InputGrid;
this->InputGrid = NULL;
// Only add if the grid falls within the output extent. Processes that do
// not contain the VOI will fail this test.
......
......@@ -144,7 +144,7 @@ public:
void CloseR()
{
this->refcount--;
if (this->refcount < 1 && ins)
if (this->refcount < 1)
{
delete ins;
ins = NULL;
......
......@@ -83,11 +83,7 @@ VarInfo::~VarInfo()
for(std::vector<StepBlock*>::iterator i = this->StepBlockIndex.begin();
i != this->StepBlockIndex.end(); ++i)
{
if(*i)
{
delete *i;
*i = NULL;
}
delete *i;
}
}
......
......@@ -593,10 +593,7 @@ int vtkGenericEnSightReader::DetermineEnSightVersion(int quiet)
} // not ensight gold
} // if we found the format section in the case file
if (fileName)
{
delete [] fileName;
}
delete [] fileName;
return -1;
}
......@@ -613,10 +610,7 @@ void vtkGenericEnSightReader::SetCaseFileName(const char* fileName)
{
return;
}
if (this->CaseFileName)
{
delete [] this->CaseFileName;
}
delete [] this->CaseFileName;
if (fileName)
{
this->CaseFileName = new char[strlen(fileName)+1];
......@@ -875,10 +869,7 @@ void vtkGenericEnSightReader::AddVariableDescription(const char* description)
strcpy(newDescriptionList[i], this->VariableDescriptions[i]);
delete [] this->VariableDescriptions[i];
}
if (this->VariableDescriptions)
{
delete [] this->VariableDescriptions;
}
delete [] this->VariableDescriptions;
// make room for new description
this->VariableDescriptions = new char *[size+1];
......@@ -1478,13 +1469,9 @@ char** vtkGenericEnSightReader::CreateStringArray(int numStrings)
void vtkGenericEnSightReader::DestroyStringArray(int numStrings,
char** strings)
{
int i;
for(i=0; i < numStrings; ++i)
for(int i=0; i < numStrings; ++i)
{
if(strings[i])
{
delete [] strings[i];
}
delete [] strings[i];
}
delete[] strings;
}
......
......@@ -1778,7 +1778,7 @@ int vtkExodusIIWriter::WriteBlockInformation()
for (size_t n = 0; n < nblocks; n ++)
{
delete [] connectivity[n];
if (this->PassDoubles && attributesD[n])
if (this->PassDoubles)
{
delete [] attributesD[n];
}
......
......@@ -91,19 +91,14 @@ vtkX3DExporter::vtkX3DExporter()
this->OutputString = NULL;
this->OutputStringLength = 0;
}
//----------------------------------------------------------------------------
vtkX3DExporter::~vtkX3DExporter()
{
this->SetFileName(0);
if (this->OutputString)
{
delete [] this->OutputString;
this->OutputString = NULL;
this->OutputStringLength = 0;
}
delete [] this->OutputString;
}
//----------------------------------------------------------------------------
void vtkX3DExporter::WriteData()
{
......
......@@ -443,11 +443,8 @@ void vtkGDALRasterReader::vtkGDALRasterReaderInternal::GenericReadData()
//----------------------------------------------------------------------------
void vtkGDALRasterReader::vtkGDALRasterReaderInternal::ReleaseData()
{
if (this->GDALData)
{
delete this->GDALData;
this->GDALData = 0;
}
delete this->GDALData;
this->GDALData = 0;
}
//-----------------------------------------------------------------------------
......@@ -650,11 +647,7 @@ vtkGDALRasterReader::vtkGDALRasterReader() : vtkImageReader2(),
//-----------------------------------------------------------------------------
vtkGDALRasterReader::~vtkGDALRasterReader()
{
if (this->Implementation)
{
delete this->Implementation;
this->Implementation = 0;
}
delete this->Implementation;
if (this->FileName)
{
......
......@@ -1248,21 +1248,15 @@ done:
/* Graph was empty */
delete [] *start;
*start = NULL;
if (adjacency)
{
delete [] *adjacency;
*adjacency = NULL;
}
if (vweights)
{
delete [] *vweights;
*vweights = NULL;
}
if (eweights)
{
delete [] *eweights;
*eweights = NULL;
}
delete [] *adjacency;
*adjacency = NULL;
delete [] *vweights;
*vweights = NULL;
delete [] *eweights;
*eweights = NULL;
}
return retVal;
......
......@@ -179,32 +179,12 @@ vtkWindBladeReader::~vtkWindBladeReader()
delete this->Internal;
delete [] this->TimeSteps;
this->TimeSteps = NULL;
if (this->VariableName)
{
delete[] this->VariableName;
}
if (this->VariableStruct)
{
delete[] this->VariableStruct;
}
if (this->VariableCompSize)
{
delete[] this->VariableCompSize;
}
if (this->VariableBasicType)
{
delete[] this->VariableBasicType;
}
if (this->VariableByteCount)
{
delete[] this->VariableByteCount;
}
if (this->VariableOffset)
{
delete[] this->VariableOffset;
}
delete[] this->VariableName;
delete[] this->VariableStruct;
delete[] this->VariableCompSize;
delete[] this->VariableBasicType;
delete[] this->VariableByteCount;
delete[] this->VariableOffset;
}
//----------------------------------------------------------------------------
......
......@@ -505,10 +505,7 @@ const char* vtkDICOMImageReader::GetTransferSyntaxUID()
{
std::string tmp = this->AppHelper->GetTransferSyntaxUID();
if (this->TransferSyntaxUID)
{
delete [] this->TransferSyntaxUID;
}
delete [] this->TransferSyntaxUID;
this->TransferSyntaxUID = new char[tmp.length()+1];
strcpy(this->TransferSyntaxUID, tmp.c_str());
this->TransferSyntaxUID[tmp.length()] = '\0';
......@@ -533,10 +530,7 @@ const char* vtkDICOMImageReader::GetPatientName()
{
std::string tmp = this->AppHelper->GetPatientName();
if (this->PatientName)
{
delete [] this->PatientName;
}
delete [] this->PatientName;
this->PatientName = new char[tmp.length()+1];
strcpy(this->PatientName, tmp.c_str());
this->PatientName[tmp.length()] = '\0';
......@@ -549,10 +543,7 @@ const char* vtkDICOMImageReader::GetStudyUID()
{
std::string tmp = this->AppHelper->GetStudyUID();
if (this->StudyUID)
{
delete [] this->StudyUID;
}
delete [] this->StudyUID;
this->StudyUID = new char[tmp.length()+1];
strcpy(this->StudyUID, tmp.c_str());
this->StudyUID[tmp.length()] = '\0';
......@@ -565,10 +556,7 @@ const char* vtkDICOMImageReader::GetStudyID()
{
std::string tmp = this->AppHelper->GetStudyID();
if (this->StudyID)
{
delete [] this->StudyID;
}
delete [] this->StudyID;
this->StudyID = new char[tmp.length()+1];
strcpy(this->StudyID, tmp.c_str());
this->StudyID[tmp.length()] = '\0';
......
Supports Markdown
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