From bdddadec19fb26d3eda03a50984c3e2a7018c3ee Mon Sep 17 00:00:00 2001 From: Pasukhin Dmitry Date: Fri, 13 Feb 2026 12:37:51 +0000 Subject: [PATCH] Coding - Remove redundant null checks before deallocation (#1077) In C++, delete/delete[] on nullptr and free(NULL) are guaranteed no-ops. This removes redundant null-check guards before these calls across 39 files, reducing code noise without behavioral change. Also simplifies map value cleanup in BRepClass3d_SolidExplorer by using iterator reference instead of redundant hash lookups. --- .../TKCAF/TNaming/TNaming_NamedShape.cxx | 14 +++------ .../TKCDF/LDOM/LDOMBasicString.cxx | 7 ++--- .../TKCDF/LDOM/LDOMParser.cxx | 6 ++-- .../TKCDF/LDOM/LDOM_MemManager.cxx | 3 +- .../TKCDF/LDOM/LDOM_XmlWriter.cxx | 16 ++-------- .../TKXSBase/Interface/Interface_MSG.cxx | 7 ++--- .../TKXSBase/Interface/Interface_ParamSet.cxx | 3 +- src/Draw/TKDraw/Draw/Draw_Viewer.cxx | 14 +++------ src/Draw/TKQADraw/QABugs/QABugs_17.cxx | 19 ++++-------- .../TKTopTest/BOPTest/BOPTest_BOPCommands.cxx | 7 ++--- .../BRepTest/BRepTest_FilletCommands.cxx | 26 +++++------------ .../BRepTest/BRepTest_SweepCommands.cxx | 13 ++------- .../ViewerTest/ViewerTest_FilletCommands.cxx | 7 ++--- .../TKMath/Poly/Poly_Triangulation.cxx | 7 ++--- .../NCollection/NCollection_BaseMap.cxx | 11 +++---- .../NCollection/NCollection_Handle.hxx | 3 +- .../NCollection/NCollection_HeapAllocator.cxx | 3 +- .../NCollection/NCollection_UtfString.cxx | 7 ++--- .../TKernel/OSD/OSD_Environment.cxx | 3 +- .../TKernel/OSD/OSD_SharedLibrary.cxx | 18 ++++-------- .../TKBO/BOPAlgo/BOPAlgo_BOP.cxx | 7 ++--- .../TKBO/BOPAlgo/BOPAlgo_Builder.cxx | 14 +++------ .../TKBO/BOPAlgo/BOPAlgo_MakerVolume.cxx | 7 ++--- .../TKBO/BOPAlgo/BOPAlgo_PaveFiller.cxx | 14 +++------ .../TKBO/BOPAlgo/BOPAlgo_Splitter.cxx | 7 ++--- .../BRepAlgoAPI/BRepAlgoAPI_BuilderAlgo.cxx | 12 +++----- .../TopOpeBRepDS/TopOpeBRepDS_connex.cxx | 28 +++++------------- .../TopOpeBRepDS/TopOpeBRepDS_samdom.cxx | 14 +++------ .../TKFeat/LocOpe/LocOpe_CSIntersector.cxx | 29 +++++-------------- .../GeomFill/GeomFill_ConstrainedFilling.cxx | 5 +--- .../IntPatch/IntPatch_Polyhedron.cxx | 9 ++---- .../IntPatch/IntPatch_PrmPrmIntersection.cxx | 7 ++--- .../IntPatch_PrmPrmIntersection_T3Bits.cxx | 7 ++--- .../IntPolyh/IntPolyh_Intersection.cxx | 18 ++++-------- .../TKHLR/HLRBRep/HLRBRep_Intersector.cxx | 11 +++---- .../BRepClass3d/BRepClass3d_SolidExplorer.cxx | 18 ++++-------- .../BRepTopAdaptor_TopolTool.cxx | 12 ++------ .../TKMeshVS/MeshVS/MeshVS_Buffer.hxx | 7 ++--- .../TKService/Image/Image_AlienPixMap.cxx | 7 ++--- 39 files changed, 123 insertions(+), 304 deletions(-) diff --git a/src/ApplicationFramework/TKCAF/TNaming/TNaming_NamedShape.cxx b/src/ApplicationFramework/TKCAF/TNaming/TNaming_NamedShape.cxx index c701be48da..a1be24845f 100644 --- a/src/ApplicationFramework/TKCAF/TNaming/TNaming_NamedShape.cxx +++ b/src/ApplicationFramework/TKCAF/TNaming/TNaming_NamedShape.cxx @@ -286,11 +286,8 @@ void TNaming_NamedShape::Clear() { q = p; p = p->nextSameAttribute; - if (q != nullptr) - { - delete q; - q = nullptr; - } + delete q; + q = nullptr; } myNode = nullptr; @@ -352,11 +349,8 @@ bool TNaming_NamedShape::AfterUndo(const occ::handle& anAttD { q = p; p = p->nextSameAttribute; - if (q != nullptr) - { - delete q; - q = nullptr; - } + delete q; + q = nullptr; } myNode = nullptr; diff --git a/src/ApplicationFramework/TKCDF/LDOM/LDOMBasicString.cxx b/src/ApplicationFramework/TKCDF/LDOM/LDOMBasicString.cxx index 1a5d88e3ca..d97eb505d9 100644 --- a/src/ApplicationFramework/TKCDF/LDOM/LDOMBasicString.cxx +++ b/src/ApplicationFramework/TKCDF/LDOM/LDOMBasicString.cxx @@ -118,8 +118,7 @@ LDOMBasicString::~LDOMBasicString() { if (myType == LDOM_AsciiFree) { - if (myVal.ptr) - delete[] (char*)myVal.ptr; + delete[] (char*)myVal.ptr; } } @@ -130,7 +129,7 @@ LDOMBasicString::~LDOMBasicString() LDOMBasicString& LDOMBasicString::operator=(const LDOM_NullPtr*) { - if (myType == LDOM_AsciiFree && myVal.ptr) + if (myType == LDOM_AsciiFree) delete[] (char*)myVal.ptr; myType = LDOM_NULL; myVal.ptr = nullptr; @@ -148,7 +147,7 @@ LDOMBasicString& LDOMBasicString::operator=(const LDOMBasicString& anOther) { return *this; } - if (myType == LDOM_AsciiFree && myVal.ptr) + if (myType == LDOM_AsciiFree) delete[] (char*)myVal.ptr; myType = anOther.Type(); switch (myType) diff --git a/src/ApplicationFramework/TKCDF/LDOM/LDOMParser.cxx b/src/ApplicationFramework/TKCDF/LDOM/LDOMParser.cxx index cb0ad06550..199f51c7d0 100644 --- a/src/ApplicationFramework/TKCDF/LDOM/LDOMParser.cxx +++ b/src/ApplicationFramework/TKCDF/LDOM/LDOMParser.cxx @@ -36,8 +36,7 @@ LDOMParser::~LDOMParser() { - if (myReader) - delete myReader; + delete myReader; } //======================================================================= @@ -145,8 +144,7 @@ bool LDOMParser::parse(std::istream& anInput, const bool theTagPerStep, const bo myError.Clear(); // Create the Reader instance - if (myReader) - delete myReader; + delete myReader; myReader = new LDOM_XmlReader(myDocument, myError, theTagPerStep); // Parse diff --git a/src/ApplicationFramework/TKCDF/LDOM/LDOM_MemManager.cxx b/src/ApplicationFramework/TKCDF/LDOM/LDOM_MemManager.cxx index 660aab6536..d7d5f54085 100644 --- a/src/ApplicationFramework/TKCDF/LDOM/LDOM_MemManager.cxx +++ b/src/ApplicationFramework/TKCDF/LDOM/LDOM_MemManager.cxx @@ -254,8 +254,7 @@ LDOM_MemManager::LDOM_MemManager(const int aBlockSize) LDOM_MemManager::~LDOM_MemManager() { delete myFirstBlock; - if (myHashTable) - delete myHashTable; + delete myHashTable; } //================================================================================================= diff --git a/src/ApplicationFramework/TKCDF/LDOM/LDOM_XmlWriter.cxx b/src/ApplicationFramework/TKCDF/LDOM/LDOM_XmlWriter.cxx index 9a3029e9ad..86b481f96c 100644 --- a/src/ApplicationFramework/TKCDF/LDOM/LDOM_XmlWriter.cxx +++ b/src/ApplicationFramework/TKCDF/LDOM/LDOM_XmlWriter.cxx @@ -177,11 +177,7 @@ LDOM_XmlWriter::LDOM_XmlWriter(const char* theEncoding) LDOM_XmlWriter::~LDOM_XmlWriter() { delete[] myEncodingName; - - if (myABuffer != nullptr) - { - delete[] myABuffer; - } + delete[] myABuffer; } //================================================================================================= @@ -417,10 +413,7 @@ void LDOM_XmlWriter::WriteAttribute(Standard_OStream& theOStream, const LDOM_Nod aLength = (int)(20 + strlen(aName)); if (aLength > myABufferLen) { - if (myABuffer != nullptr) - { - delete[] myABuffer; - } + delete[] myABuffer; myABuffer = new char[aLength + 1]; myABufferLen = aLength; @@ -452,10 +445,7 @@ void LDOM_XmlWriter::WriteAttribute(Standard_OStream& theOStream, const LDOM_Nod if (aLength > myABufferLen) { - if (myABuffer != nullptr) - { - delete[] myABuffer; - } + delete[] myABuffer; myABuffer = new char[aLength + 1]; myABufferLen = aLength; diff --git a/src/DataExchange/TKXSBase/Interface/Interface_MSG.cxx b/src/DataExchange/TKXSBase/Interface/Interface_MSG.cxx index f6b7a4077c..7c1630ee9b 100644 --- a/src/DataExchange/TKXSBase/Interface/Interface_MSG.cxx +++ b/src/DataExchange/TKXSBase/Interface/Interface_MSG.cxx @@ -102,11 +102,8 @@ const char* Interface_MSG::Value() const void Interface_MSG::Destroy() { - if (theval) - { - delete[] theval; - theval = nullptr; - } + delete[] theval; + theval = nullptr; } Interface_MSG::operator const char*() const diff --git a/src/DataExchange/TKXSBase/Interface/Interface_ParamSet.cxx b/src/DataExchange/TKXSBase/Interface/Interface_ParamSet.cxx index bc33f7e679..3076aecb3c 100644 --- a/src/DataExchange/TKXSBase/Interface/Interface_ParamSet.cxx +++ b/src/DataExchange/TKXSBase/Interface/Interface_ParamSet.cxx @@ -174,8 +174,7 @@ void Interface_ParamSet::Destroy() // if (!thenext.IsNull()) thenext->Destroy(); thenext.Nullify(); // "Manual" destruction (direct memory management) - if (theval) - delete[] theval; + delete[] theval; theval = nullptr; thelist->Clear(); thelist.Nullify(); diff --git a/src/Draw/TKDraw/Draw/Draw_Viewer.cxx b/src/Draw/TKDraw/Draw/Draw_Viewer.cxx index 9bef742843..dfb70e11a0 100644 --- a/src/Draw/TKDraw/Draw/Draw_Viewer.cxx +++ b/src/Draw/TKDraw/Draw/Draw_Viewer.cxx @@ -530,11 +530,8 @@ void Draw_Viewer::RemoveView(const int id) { if (Draw_Batch) return; - if (myViews[id]) - { - delete myViews[id]; - myViews[id] = nullptr; - } + delete myViews[id]; + myViews[id] = nullptr; } //================================================================================================= @@ -724,11 +721,8 @@ void Draw_Viewer::DeleteView(const int id) { if (Draw_Batch) return; - if (myViews[id] != nullptr) - { - delete myViews[id]; - myViews[id] = nullptr; - } + delete myViews[id]; + myViews[id] = nullptr; } //================================================================================================= diff --git a/src/Draw/TKQADraw/QABugs/QABugs_17.cxx b/src/Draw/TKQADraw/QABugs/QABugs_17.cxx index 377ee3ca8d..2fc27c6bb4 100644 --- a/src/Draw/TKQADraw/QABugs/QABugs_17.cxx +++ b/src/Draw/TKQADraw/QABugs/QABugs_17.cxx @@ -557,11 +557,8 @@ static void printtolblend(Draw_Interpretor& di) static int MKEVOL(Draw_Interpretor& di, int narg, const char** a) { - if (Rake != nullptr) - { - delete Rake; - Rake = nullptr; - } + delete Rake; + Rake = nullptr; printtolblend(di); if (narg < 3) return 1; @@ -632,18 +629,12 @@ static int BUILDEVOL(Draw_Interpretor& di, int, const char**) { TopoDS_Shape result = Rake->Shape(); DBRep::Set(name, result); - if (Rake != nullptr) - { - delete Rake; - Rake = nullptr; - } - return 0; - } - if (Rake != nullptr) - { delete Rake; Rake = nullptr; + return 0; } + delete Rake; + Rake = nullptr; return 1; } diff --git a/src/Draw/TKTopTest/BOPTest/BOPTest_BOPCommands.cxx b/src/Draw/TKTopTest/BOPTest/BOPTest_BOPCommands.cxx index c289c493a3..190b67ac67 100644 --- a/src/Draw/TKTopTest/BOPTest/BOPTest_BOPCommands.cxx +++ b/src/Draw/TKTopTest/BOPTest/BOPTest_BOPCommands.cxx @@ -142,11 +142,8 @@ int bop(Draw_Interpretor& di, int n, const char** a) aLC.Append(aS1); aLC.Append(aS2); // - if (pPF != nullptr) - { - delete pPF; - pPF = nullptr; - } + delete pPF; + pPF = nullptr; occ::handle aAL = NCollection_BaseAllocator::CommonBaseAllocator(); pPF = new BOPAlgo_PaveFiller(aAL); // diff --git a/src/Draw/TKTopTest/BRepTest/BRepTest_FilletCommands.cxx b/src/Draw/TKTopTest/BRepTest/BRepTest_FilletCommands.cxx index 16c515b521..0d8ebaa8c6 100644 --- a/src/Draw/TKTopTest/BRepTest/BRepTest_FilletCommands.cxx +++ b/src/Draw/TKTopTest/BRepTest/BRepTest_FilletCommands.cxx @@ -147,11 +147,8 @@ static int tolblend(Draw_Interpretor& di, int narg, const char** a) static int BLEND(Draw_Interpretor& di, int narg, const char** a) { - if (Rakk != nullptr) - { - delete Rakk; - Rakk = nullptr; - } + delete Rakk; + Rakk = nullptr; printtolblend(di); if (narg < 5) return 1; @@ -276,11 +273,8 @@ static int CheckHist(Draw_Interpretor& di, int, const char**) static int MKEVOL(Draw_Interpretor& di, int narg, const char** a) { - if (Rake != nullptr) - { - delete Rake; - Rake = nullptr; - } + delete Rake; + Rake = nullptr; printtolblend(di); if (narg < 3) return 1; @@ -343,18 +337,12 @@ static int BUILDEVOL(Draw_Interpretor& di, int, const char**) { TopoDS_Shape result = Rake->Shape(); DBRep::Set(name, result); - if (Rake != nullptr) - { - delete Rake; - Rake = nullptr; - } - return 0; - } - if (Rake != nullptr) - { delete Rake; Rake = nullptr; + return 0; } + delete Rake; + Rake = nullptr; return 1; } diff --git a/src/Draw/TKTopTest/BRepTest/BRepTest_SweepCommands.cxx b/src/Draw/TKTopTest/BRepTest/BRepTest_SweepCommands.cxx index bafce16ec8..9d9700a5c1 100644 --- a/src/Draw/TKTopTest/BRepTest/BRepTest_SweepCommands.cxx +++ b/src/Draw/TKTopTest/BRepTest/BRepTest_SweepCommands.cxx @@ -467,11 +467,7 @@ int thrusections(Draw_Interpretor& di, int n, const char** a) bool issolid = (Draw::Atoi(a[index]) == 1); bool isruled = (Draw::Atoi(a[index + 1]) == 1); - if (Generator != nullptr) - { - delete Generator; - Generator = nullptr; - } + delete Generator; Generator = new BRepOffsetAPI_ThruSections(issolid, isruled); bool IsMutableInput = true; int NbEdges = 0; @@ -568,11 +564,8 @@ static int mksweep(Draw_Interpretor& di, int n, const char** a) TopoDS_Shape Spine = DBRep::Get(a[1], TopAbs_WIRE); if (Spine.IsNull()) return 1; - if (Sweep != nullptr) - { - delete Sweep; - Sweep = nullptr; - } + delete Sweep; + Sweep = nullptr; if (n > 2 && n <= 5) { diff --git a/src/Draw/TKViewerTest/ViewerTest/ViewerTest_FilletCommands.cxx b/src/Draw/TKViewerTest/ViewerTest/ViewerTest_FilletCommands.cxx index 7f0e5f33f4..f0c2ef5fa9 100644 --- a/src/Draw/TKViewerTest/ViewerTest/ViewerTest_FilletCommands.cxx +++ b/src/Draw/TKViewerTest/ViewerTest/ViewerTest_FilletCommands.cxx @@ -60,11 +60,8 @@ static void printtolblend(Draw_Interpretor& di) static int VBLEND(Draw_Interpretor& di, int narg, const char** a) { - if (Rakk != nullptr) - { - delete Rakk; - Rakk = nullptr; - } + delete Rakk; + Rakk = nullptr; printtolblend(di); if (narg < 5) return 1; diff --git a/src/FoundationClasses/TKMath/Poly/Poly_Triangulation.cxx b/src/FoundationClasses/TKMath/Poly/Poly_Triangulation.cxx index f9b182722e..f6f330b384 100644 --- a/src/FoundationClasses/TKMath/Poly/Poly_Triangulation.cxx +++ b/src/FoundationClasses/TKMath/Poly/Poly_Triangulation.cxx @@ -365,11 +365,8 @@ void Poly_Triangulation::SetCachedMinMax(const Bnd_Box& theBox) void Poly_Triangulation::unsetCachedMinMax() { - if (myCachedMinMax != nullptr) - { - delete myCachedMinMax; - myCachedMinMax = nullptr; - } + delete myCachedMinMax; + myCachedMinMax = nullptr; } //================================================================================================= diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_BaseMap.cxx b/src/FoundationClasses/TKernel/NCollection/NCollection_BaseMap.cxx index ebbb128c30..6c1dbf5976 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_BaseMap.cxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_BaseMap.cxx @@ -52,9 +52,8 @@ void NCollection_BaseMap::EndResize(const int theNbBuckets, NCollection_ListNode** data2) noexcept { (void)theNbBuckets; // obsolete parameter - if (myData1) - Standard::Free(myData1); - if (myData2 && isDouble) + Standard::Free(myData1); + if (isDouble) Standard::Free(myData2); myNbBuckets = N; myData1 = data1; @@ -90,10 +89,8 @@ void NCollection_BaseMap::Destroy(NCollection_DelMapNode fDel, bool doReleaseMem } if (doReleaseMemory) { - if (myData1) - Standard::Free(myData1); - if (myData2) - Standard::Free(myData2); + Standard::Free(myData1); + Standard::Free(myData2); myData1 = myData2 = nullptr; } } diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_Handle.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_Handle.hxx index 144d3ac2c9..40205ffbaa 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_Handle.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_Handle.hxx @@ -46,8 +46,7 @@ private: //! Destructor deletes the object ~Ptr() override { - if (myPtr) - delete myPtr; + delete myPtr; myPtr = nullptr; } diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_HeapAllocator.cxx b/src/FoundationClasses/TKernel/NCollection/NCollection_HeapAllocator.cxx index 9f0288cde0..121bafff87 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_HeapAllocator.cxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_HeapAllocator.cxx @@ -38,8 +38,7 @@ void* NCollection_HeapAllocator::Allocate(const size_t theSize) void NCollection_HeapAllocator::Free(void* anAddress) { - if (anAddress) - free(anAddress); + free(anAddress); } //================================================================================================= diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_UtfString.cxx b/src/FoundationClasses/TKernel/NCollection/NCollection_UtfString.cxx index 42e8074f43..812764248c 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_UtfString.cxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_UtfString.cxx @@ -31,11 +31,8 @@ NCollection_UtfStringTool::~NCollection_UtfStringTool() wchar_t* NCollection_UtfStringTool::FromLocale(const char* theString) { - if (myWideBuffer != nullptr) - { - delete[] myWideBuffer; - myWideBuffer = nullptr; - } + delete[] myWideBuffer; + myWideBuffer = nullptr; #if defined(_WIN32) // use WinAPI diff --git a/src/FoundationClasses/TKernel/OSD/OSD_Environment.cxx b/src/FoundationClasses/TKernel/OSD/OSD_Environment.cxx index 150c97f459..a4b50bfc8e 100644 --- a/src/FoundationClasses/TKernel/OSD/OSD_Environment.cxx +++ b/src/FoundationClasses/TKernel/OSD/OSD_Environment.cxx @@ -165,8 +165,7 @@ void OSD_Environment::Build() putenv(buffer[index]); // then (and only then!) free old entry, if existed - if (old_value) - free(old_value); + free(old_value); // check the result char* result = getenv(myName.ToCString()); diff --git a/src/FoundationClasses/TKernel/OSD/OSD_SharedLibrary.cxx b/src/FoundationClasses/TKernel/OSD/OSD_SharedLibrary.cxx index 5103742ff4..36c5d39415 100644 --- a/src/FoundationClasses/TKernel/OSD/OSD_SharedLibrary.cxx +++ b/src/FoundationClasses/TKernel/OSD/OSD_SharedLibrary.cxx @@ -196,12 +196,9 @@ const char* OSD_SharedLibrary::DlError() const void OSD_SharedLibrary::Destroy() { - if (myName != nullptr) - { - delete[] myName; - myName = nullptr; - myHandle = nullptr; - } + delete[] myName; + myName = nullptr; + myHandle = nullptr; } #else @@ -253,9 +250,7 @@ void OSD_SharedLibrary ::SetName(const char* const aName) OSD_Path path(aName); TCollection_AsciiString name(aName); - if (myName != NULL) - - delete[] myName; + delete[] myName; myName = new char[strlen(aName) + 1]; @@ -343,10 +338,7 @@ const char* OSD_SharedLibrary ::DlError() const void OSD_SharedLibrary ::Destroy() { - - if (myName != NULL) - delete[] myName; - + delete[] myName; } // end OSD_SharedLibrary :: Destroy #endif diff --git a/src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_BOP.cxx b/src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_BOP.cxx index f9a43d351f..2da583c014 100644 --- a/src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_BOP.cxx +++ b/src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_BOP.cxx @@ -360,11 +360,8 @@ void BOPAlgo_BOP::Perform(const Message_ProgressRange& theRange) // if (myEntryPoint == 1) { - if (myPaveFiller) - { - delete myPaveFiller; - myPaveFiller = nullptr; - } + delete myPaveFiller; + myPaveFiller = nullptr; } // aAllocator = NCollection_BaseAllocator::CommonBaseAllocator(); diff --git a/src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_Builder.cxx b/src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_Builder.cxx index bc9d0dae82..e13b437d66 100644 --- a/src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_Builder.cxx +++ b/src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_Builder.cxx @@ -80,11 +80,8 @@ BOPAlgo_Builder::~BOPAlgo_Builder() { if (myEntryPoint == 1) { - if (myPaveFiller) - { - delete myPaveFiller; - myPaveFiller = nullptr; - } + delete myPaveFiller; + myPaveFiller = nullptr; } } @@ -173,11 +170,8 @@ void BOPAlgo_Builder::Perform(const Message_ProgressRange& theRange) // if (myEntryPoint == 1) { - if (myPaveFiller) - { - delete myPaveFiller; - myPaveFiller = nullptr; - } + delete myPaveFiller; + myPaveFiller = nullptr; } // occ::handle aAllocator = diff --git a/src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_MakerVolume.cxx b/src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_MakerVolume.cxx index 8211ffa9f2..a7f4473bd0 100644 --- a/src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_MakerVolume.cxx +++ b/src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_MakerVolume.cxx @@ -53,11 +53,8 @@ void BOPAlgo_MakerVolume::Perform(const Message_ProgressRange& theRange) // if (myEntryPoint == 1) { - if (myPaveFiller) - { - delete myPaveFiller; - myPaveFiller = nullptr; - } + delete myPaveFiller; + myPaveFiller = nullptr; } // occ::handle aAllocator = diff --git a/src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_PaveFiller.cxx b/src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_PaveFiller.cxx index ad85a301ea..96c21f4f19 100644 --- a/src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_PaveFiller.cxx +++ b/src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_PaveFiller.cxx @@ -135,16 +135,10 @@ bool BOPAlgo_PaveFiller::IsPrimary() const void BOPAlgo_PaveFiller::Clear() { BOPAlgo_Algo::Clear(); - if (myIterator) - { - delete myIterator; - myIterator = nullptr; - } - if (myDS) - { - delete myDS; - myDS = nullptr; - } + delete myIterator; + myIterator = nullptr; + delete myDS; + myDS = nullptr; myIncreasedSS.Clear(); } diff --git a/src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_Splitter.cxx b/src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_Splitter.cxx index a91de00112..700ae63e0a 100644 --- a/src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_Splitter.cxx +++ b/src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_Splitter.cxx @@ -57,11 +57,8 @@ void BOPAlgo_Splitter::Perform(const Message_ProgressRange& theRange) // if (myEntryPoint == 1) { - if (myPaveFiller) - { - delete myPaveFiller; - myPaveFiller = nullptr; - } + delete myPaveFiller; + myPaveFiller = nullptr; } // // prepare shapes for intersection diff --git a/src/ModelingAlgorithms/TKBO/BRepAlgoAPI/BRepAlgoAPI_BuilderAlgo.cxx b/src/ModelingAlgorithms/TKBO/BRepAlgoAPI/BRepAlgoAPI_BuilderAlgo.cxx index b4bc0e50c7..680d9d03a5 100644 --- a/src/ModelingAlgorithms/TKBO/BRepAlgoAPI/BRepAlgoAPI_BuilderAlgo.cxx +++ b/src/ModelingAlgorithms/TKBO/BRepAlgoAPI/BRepAlgoAPI_BuilderAlgo.cxx @@ -58,16 +58,13 @@ BRepAlgoAPI_BuilderAlgo::~BRepAlgoAPI_BuilderAlgo() void BRepAlgoAPI_BuilderAlgo::Clear() { BRepAlgoAPI_Algo::Clear(); - if (myDSFiller && myIsIntersectionNeeded) + if (myIsIntersectionNeeded) { delete myDSFiller; myDSFiller = nullptr; } - if (myBuilder) - { - delete myBuilder; - myBuilder = nullptr; - } + delete myBuilder; + myBuilder = nullptr; if (myHistory) myHistory.Nullify(); @@ -107,8 +104,7 @@ void BRepAlgoAPI_BuilderAlgo::IntersectShapes(const NCollection_List* Ghds; void FDSSDM_Close() { - if (Gps1) - { - delete Gps1; - Gps1 = nullptr; - } + delete Gps1; + Gps1 = nullptr; // - if (Gps2) - { - delete Gps2; - Gps2 = nullptr; - } + delete Gps2; + Gps2 = nullptr; } // modified by NIZNHY-PKV Sun Dec 15 17:56:02 2002 t diff --git a/src/ModelingAlgorithms/TKFeat/LocOpe/LocOpe_CSIntersector.cxx b/src/ModelingAlgorithms/TKFeat/LocOpe/LocOpe_CSIntersector.cxx index 63c8a26283..90a5ab570b 100644 --- a/src/ModelingAlgorithms/TKFeat/LocOpe/LocOpe_CSIntersector.cxx +++ b/src/ModelingAlgorithms/TKFeat/LocOpe/LocOpe_CSIntersector.cxx @@ -59,11 +59,8 @@ void LocOpe_CSIntersector::Init(const TopoDS_Shape& S) { myDone = false; myShape = S; - if (myPoints != nullptr) - { - delete[] (NCollection_Sequence*)myPoints; - myPoints = nullptr; - } + delete[] (NCollection_Sequence*)myPoints; + myPoints = nullptr; myNbelem = 0; } @@ -78,10 +75,7 @@ void LocOpe_CSIntersector::Perform(const NCollection_Sequence& Slin) myDone = false; myNbelem = Slin.Length(); - if (myPoints != nullptr) - { - delete[] (NCollection_Sequence*)myPoints; - } + delete[] (NCollection_Sequence*)myPoints; myPoints = (NCollection_Sequence*)new NCollection_Sequence[myNbelem]; @@ -115,10 +109,7 @@ void LocOpe_CSIntersector::Perform(const NCollection_Sequence& Scir) myDone = false; myNbelem = Scir.Length(); - if (myPoints != nullptr) - { - delete[] (NCollection_Sequence*)myPoints; - } + delete[] (NCollection_Sequence*)myPoints; myPoints = (NCollection_Sequence*)new NCollection_Sequence[myNbelem]; @@ -156,10 +147,7 @@ void LocOpe_CSIntersector::Perform(const NCollection_Sequence*)myPoints; - } + delete[] (NCollection_Sequence*)myPoints; myPoints = (NCollection_Sequence*)new NCollection_Sequence[myNbelem]; @@ -222,11 +210,8 @@ const LocOpe_PntFace& LocOpe_CSIntersector::Point(const int I, const int Index) void LocOpe_CSIntersector::Destroy() { - if (myPoints != nullptr) - { - delete[] (NCollection_Sequence*)myPoints; - myPoints = nullptr; - } + delete[] (NCollection_Sequence*)myPoints; + myPoints = nullptr; } //================================================================================================= diff --git a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_ConstrainedFilling.cxx b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_ConstrainedFilling.cxx index 42ec53a3d8..052e7717cd 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_ConstrainedFilling.cxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_ConstrainedFilling.cxx @@ -1248,10 +1248,7 @@ void GeomFill_ConstrainedFilling::PerformS1() // Un petit menage for (i = 0; i <= 3; i++) { - if (nt[i]) - { - delete[] nt[i]; - } + delete[] nt[i]; } } diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntPatch/IntPatch_Polyhedron.cxx b/src/ModelingAlgorithms/TKGeomAlgo/IntPatch/IntPatch_Polyhedron.cxx index 03b71aacef..69bb4c69bd 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/IntPatch/IntPatch_Polyhedron.cxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/IntPatch/IntPatch_Polyhedron.cxx @@ -57,14 +57,11 @@ static int NbPOnV(const occ::handle& S) void IntPatch_Polyhedron::Destroy() { gp_Pnt* CMyPnts = (gp_Pnt*)C_MyPnts; - if (C_MyPnts) - delete[] CMyPnts; + delete[] CMyPnts; double* CMyU = (double*)C_MyU; - if (C_MyU) - delete[] CMyU; + delete[] CMyU; double* CMyV = (double*)C_MyV; - if (C_MyV) - delete[] CMyV; + delete[] CMyV; C_MyPnts = C_MyU = C_MyV = nullptr; } diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntPatch/IntPatch_PrmPrmIntersection.cxx b/src/ModelingAlgorithms/TKGeomAlgo/IntPatch/IntPatch_PrmPrmIntersection.cxx index 8aedbca3cf..b894a32e12 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/IntPatch/IntPatch_PrmPrmIntersection.cxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/IntPatch/IntPatch_PrmPrmIntersection.cxx @@ -2392,11 +2392,8 @@ void IntPatch_PrmPrmIntersection::Perform(const occ::handle& done = Interference.IsDone(); if (!done) { - if (pInterference) - { - delete pInterference; - pInterference = nullptr; - } + delete pInterference; + pInterference = nullptr; return; } diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntPatch/IntPatch_PrmPrmIntersection_T3Bits.cxx b/src/ModelingAlgorithms/TKGeomAlgo/IntPatch/IntPatch_PrmPrmIntersection_T3Bits.cxx index f7c5e5002c..424ad177c7 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/IntPatch/IntPatch_PrmPrmIntersection_T3Bits.cxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/IntPatch/IntPatch_PrmPrmIntersection_T3Bits.cxx @@ -30,11 +30,8 @@ IntPatch_PrmPrmIntersection_T3Bits::IntPatch_PrmPrmIntersection_T3Bits(const int IntPatch_PrmPrmIntersection_T3Bits::~IntPatch_PrmPrmIntersection_T3Bits() { - if (p) - { - delete[] p; - p = nullptr; - } + delete[] p; + p = nullptr; } void IntPatch_PrmPrmIntersection_T3Bits::ResetAnd() diff --git a/src/ModelingAlgorithms/TKGeomAlgo/IntPolyh/IntPolyh_Intersection.cxx b/src/ModelingAlgorithms/TKGeomAlgo/IntPolyh/IntPolyh_Intersection.cxx index ba0c99a9a5..3d4ab8d38f 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/IntPolyh/IntPolyh_Intersection.cxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/IntPolyh/IntPolyh_Intersection.cxx @@ -180,8 +180,7 @@ void IntPolyh_Intersection::Perform(const NCollection_Array1& theUPars1, { // Intersection not done myIsDone = false; - if (pMaillageStd) - delete pMaillageStd; + delete pMaillageStd; return; } @@ -228,19 +227,14 @@ void IntPolyh_Intersection::Perform(const NCollection_Array1& theUPars1, } // Clean up - if (pMaillageFF) - delete pMaillageFF; - if (pMaillageFR) - delete pMaillageFR; - if (pMaillageRF) - delete pMaillageRF; - if (pMaillageRR) - delete pMaillageRR; + delete pMaillageFF; + delete pMaillageFR; + delete pMaillageRF; + delete pMaillageRR; } // clean up - if (pMaillageStd) - delete pMaillageStd; + delete pMaillageStd; } //================================================================================================= diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_Intersector.cxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_Intersector.cxx index b33349820e..cdcc2885d7 100644 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_Intersector.cxx +++ b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_Intersector.cxx @@ -484,11 +484,8 @@ void HLRBRep_Intersector::SimulateOnePoint(HLRBRep_EdgeData* theEdge1, void HLRBRep_Intersector::Load(HLRBRep_Surface* theSurface) { mySurface = theSurface; - if (myPolyhedron != nullptr) - { - delete myPolyhedron; - myPolyhedron = nullptr; - } + delete myPolyhedron; + myPolyhedron = nullptr; } //================================================================================================= @@ -668,8 +665,8 @@ const IntCurveSurface_IntersectionSegment& HLRBRep_Intersector::CSSegment(const void HLRBRep_Intersector::Destroy() { - if (myPolyhedron != nullptr) - delete myPolyhedron; + delete myPolyhedron; + myPolyhedron = nullptr; } /* ******************************************************************************** diff --git a/src/ModelingAlgorithms/TKTopAlgo/BRepClass3d/BRepClass3d_SolidExplorer.cxx b/src/ModelingAlgorithms/TKTopAlgo/BRepClass3d/BRepClass3d_SolidExplorer.cxx index edbf4d1a62..0bb69d079a 100644 --- a/src/ModelingAlgorithms/TKTopAlgo/BRepClass3d/BRepClass3d_SolidExplorer.cxx +++ b/src/ModelingAlgorithms/TKTopAlgo/BRepClass3d/BRepClass3d_SolidExplorer.cxx @@ -835,12 +835,9 @@ void BRepClass3d_SolidExplorer::Destroy() NCollection_DataMap::Iterator iter(myMapOfInter); for (; iter.More(); iter.Next()) { - void* ptr = iter.Value(); - if (ptr) - { - delete (IntCurvesFace_Intersector*)ptr; - myMapOfInter.ChangeFind(iter.Key()) = nullptr; - } + void*& aPtr = iter.ChangeValue(); + delete (IntCurvesFace_Intersector*)aPtr; + aPtr = nullptr; } myMapOfInter.Clear(); } @@ -860,12 +857,9 @@ void BRepClass3d_SolidExplorer::InitShape(const TopoDS_Shape& S) NCollection_DataMap::Iterator iter(myMapOfInter); for (; iter.More(); iter.Next()) { - void* ptr = iter.Value(); - if (ptr) - { - delete (IntCurvesFace_Intersector*)ptr; - myMapOfInter.ChangeFind(iter.Key()) = nullptr; - } + void*& aPtr = iter.ChangeValue(); + delete (IntCurvesFace_Intersector*)aPtr; + aPtr = nullptr; } myMapOfInter.Clear(); diff --git a/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/BRepTopAdaptor_TopolTool.cxx b/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/BRepTopAdaptor_TopolTool.cxx index a09f923642..fae969e65b 100644 --- a/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/BRepTopAdaptor_TopolTool.cxx +++ b/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/BRepTopAdaptor_TopolTool.cxx @@ -78,10 +78,7 @@ void BRepTopAdaptor_TopolTool::Initialize(const occ::handle& TopoDS_Shape s_wnt = brhs->Face(); s_wnt.Orientation(TopAbs_FORWARD); myFace = TopoDS::Face(s_wnt); - if (myFClass2d != nullptr) - { - delete (BRepTopAdaptor_FClass2d*)myFClass2d; - } + delete (BRepTopAdaptor_FClass2d*)myFClass2d; myFClass2d = nullptr; myNbSamplesU = -1; myS = S; @@ -205,11 +202,8 @@ bool BRepTopAdaptor_TopolTool::IsThePointOn(const gp_Pnt2d& P, void BRepTopAdaptor_TopolTool::Destroy() { - if (myFClass2d != nullptr) - { - delete (BRepTopAdaptor_FClass2d*)myFClass2d; - myFClass2d = nullptr; - } + delete (BRepTopAdaptor_FClass2d*)myFClass2d; + myFClass2d = nullptr; } //================================================================================================= diff --git a/src/Visualization/TKMeshVS/MeshVS/MeshVS_Buffer.hxx b/src/Visualization/TKMeshVS/MeshVS/MeshVS_Buffer.hxx index f5b88cfd6f..194a7e2a7f 100644 --- a/src/Visualization/TKMeshVS/MeshVS/MeshVS_Buffer.hxx +++ b/src/Visualization/TKMeshVS/MeshVS/MeshVS_Buffer.hxx @@ -44,11 +44,8 @@ public: //! Destructor ~MeshVS_Buffer() { - if (myDynData) - { - Standard::Free(myDynData); - myDynData = nullptr; - } + Standard::Free(myDynData); + myDynData = nullptr; } //! Cast the buffer to the void pointer diff --git a/src/Visualization/TKService/Image/Image_AlienPixMap.cxx b/src/Visualization/TKService/Image/Image_AlienPixMap.cxx index 1146f2a407..238efdcc42 100644 --- a/src/Visualization/TKService/Image/Image_AlienPixMap.cxx +++ b/src/Visualization/TKService/Image/Image_AlienPixMap.cxx @@ -608,11 +608,8 @@ void Image_AlienPixMap::Clear() myPalette = NULL; } #elif defined(__EMSCRIPTEN__) - if (myLibImage != NULL) - { - free((void*)myLibImage); - myLibImage = NULL; - } + free((void*)myLibImage); + myLibImage = NULL; #endif }