From aabb991fa6459f71e1d069aaf77dc34a3b2c5e00 Mon Sep 17 00:00:00 2001 From: eap Date: Wed, 19 Jun 2013 14:21:33 +0000 Subject: [PATCH] 0022232: [CEA 837] Memory corruption in GEOM/SMESH that leads to segfault on debian64 Fix "Conditional jump or move depends on uninitialised value(s)" valgrind error - initialize NETGENPlugin_NetgenLibWrapper::isComputeOk --- src/NETGENPlugin/NETGENPlugin_Mesher.cxx | 31 +++++++++---------- src/NETGENPlugin/NETGENPlugin_Mesher.hxx | 11 ++++--- .../NETGENPlugin_NETGEN_2D_ONLY.cxx | 8 +---- src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx | 4 +-- 4 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/NETGENPlugin/NETGENPlugin_Mesher.cxx b/src/NETGENPlugin/NETGENPlugin_Mesher.cxx index b71aa80..e24f9c0 100644 --- a/src/NETGENPlugin/NETGENPlugin_Mesher.cxx +++ b/src/NETGENPlugin/NETGENPlugin_Mesher.cxx @@ -2055,14 +2055,8 @@ namespace bool NETGENPlugin_Mesher::Compute() { - NETGENPlugin_NetgenLibWrapper aNgLib; - -// Internal method is needed to get result of computation - return aNgLib.isComputeOk = _compute( &aNgLib ); -} + NETGENPlugin_NetgenLibWrapper ngLib; -bool NETGENPlugin_Mesher::_compute( NETGENPlugin_NetgenLibWrapper* ngLib ) -{ netgen::MeshingParameters& mparams = netgen::mparam; MESSAGE("Compute with:\n" " max size = " << mparams.maxh << "\n" @@ -2153,7 +2147,7 @@ bool NETGENPlugin_Mesher::_compute( NETGENPlugin_NetgenLibWrapper* ngLib ) err = 0; //- MESHCONST_ANALYSE isn't so important step if ( !ngMesh ) return false; - ngLib->setMesh(( Ng_Mesh*) ngMesh ); + ngLib.setMesh(( Ng_Mesh*) ngMesh ); ngMesh->ClearFaceDescriptors(); // we make descriptors our-self @@ -2637,6 +2631,8 @@ bool NETGENPlugin_Mesher::_compute( NETGENPlugin_NetgenLibWrapper* ngLib ) err = 0; // no fatal errors, only warnings } + ngLib._isComputeOk = !err; + return !err; } @@ -3469,9 +3465,12 @@ SMESH_Mesh& NETGENPlugin_Internals::getMesh() const NETGENPlugin_NetgenLibWrapper::NETGENPlugin_NetgenLibWrapper() { Ng_Init(); - myOutputFile = getOutputFileName(); - netgen::mycout = new ofstream ( myOutputFile.c_str() ); - cout << "NOTE: netgen output was redirected to file " << myOutputFile << endl; + + _isComputeOk = false; + _outputFileName = getOutputFileName(); + netgen::mycout = new ofstream ( _outputFileName.c_str() ); + cout << "NOTE: netgen output was redirected to file " << _outputFileName << endl; + _ngMesh = Ng_NewMesh(); } @@ -3486,8 +3485,8 @@ NETGENPlugin_NetgenLibWrapper::~NETGENPlugin_NetgenLibWrapper() Ng_DeleteMesh( _ngMesh ); Ng_Exit(); NETGENPlugin_Mesher::RemoveTmpFiles(); - if( isComputeOk ) - RemoveOutputFile(); + if( _isComputeOk ) + removeOutputFile(); } //================================================================================ @@ -3529,12 +3528,12 @@ std::string NETGENPlugin_NetgenLibWrapper::getOutputFileName() */ //================================================================================ -void NETGENPlugin_NetgenLibWrapper::RemoveOutputFile() +void NETGENPlugin_NetgenLibWrapper::removeOutputFile() { - string tmpDir = SALOMEDS_Tool::GetDirFromPath( myOutputFile ); + string tmpDir = SALOMEDS_Tool::GetDirFromPath( _outputFileName ); SALOMEDS::ListOfFileNames_var aFiles = new SALOMEDS::ListOfFileNames; aFiles->length(1); - std::string aFileName = SALOMEDS_Tool::GetNameFromPath( myOutputFile ) + ".out"; + std::string aFileName = SALOMEDS_Tool::GetNameFromPath( _outputFileName ) + ".out"; aFiles[0] = aFileName.c_str(); if ( netgen::mycout) { diff --git a/src/NETGENPlugin/NETGENPlugin_Mesher.hxx b/src/NETGENPlugin/NETGENPlugin_Mesher.hxx index f7bc370..e8736a2 100644 --- a/src/NETGENPlugin/NETGENPlugin_Mesher.hxx +++ b/src/NETGENPlugin/NETGENPlugin_Mesher.hxx @@ -48,7 +48,6 @@ class SMESH_Mesh; class SMESH_Comment; class SMESHDS_Mesh; class TopoDS_Shape; -class TopTools_DataMapOfShapeShape; class TopTools_IndexedMapOfShape; class NETGENPlugin_Hypothesis; class NETGENPlugin_SimpleHypothesis_2D; @@ -81,14 +80,17 @@ struct NETGENPlugin_ngMeshInfo struct NETGENPLUGIN_EXPORT NETGENPlugin_NetgenLibWrapper { - std::string myOutputFile; - bool isComputeOk; + bool _isComputeOk; nglib::Ng_Mesh * _ngMesh; + NETGENPlugin_NetgenLibWrapper(); ~NETGENPlugin_NetgenLibWrapper(); void setMesh( nglib::Ng_Mesh* mesh ); + + private: std::string getOutputFileName(); - void RemoveOutputFile(); + void removeOutputFile(); + std::string _outputFileName; }; //============================================================================= @@ -169,7 +171,6 @@ class NETGENPLUGIN_EXPORT NETGENPlugin_Mesher const std::string& pyFile); // debug private: - bool _compute( NETGENPlugin_NetgenLibWrapper* ngLib ); SMESH_Mesh* _mesh; const TopoDS_Shape& _shape; diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx index 0aac90b..a8c887e 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx @@ -180,10 +180,7 @@ bool NETGENPlugin_NETGEN_2D_ONLY::CheckHypothesis (SMESH_Mesh& aMesh, bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) { -#ifdef WITH_SMESH_CANCEL_COMPUTE netgen::multithread.terminate = 0; -#endif - MESSAGE("NETGENPlugin_NETGEN_2D_ONLY::Compute()"); SMESHDS_Mesh* meshDS = aMesh.GetMeshDS(); int faceID = meshDS->ShapeToIndex( aShape ); @@ -294,10 +291,8 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, #else err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); #endif -#ifdef WITH_SMESH_CANCEL_COMPUTE if(netgen::multithread.terminate) return false; -#endif if ( err ) error(SMESH_Comment("Error in netgen::OCCGenerateMesh() at ") << netgen::multithread.task); } @@ -367,16 +362,15 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, } } + ngLib._isComputeOk = !err; return !err; } -#ifdef WITH_SMESH_CANCEL_COMPUTE void NETGENPlugin_NETGEN_2D_ONLY::CancelCompute() { SMESH_Algo::CancelCompute(); netgen::multithread.terminate = 1; } -#endif //============================================================================= /*! diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx index 500f374..cc05f2a 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx @@ -325,7 +325,7 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, // Generate the volume mesh // ------------------------- - return compute( aMesh, helper, nodeVec, Netgen_mesh); + return ( ngLib._isComputeOk = compute( aMesh, helper, nodeVec, Netgen_mesh)); } //================================================================================ @@ -564,7 +564,7 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, // Generate the volume mesh // ------------------------- - return compute( aMesh, *aHelper, nodeVec, Netgen_mesh); + return ( ngLib._isComputeOk = compute( aMesh, *aHelper, nodeVec, Netgen_mesh)); } void NETGENPlugin_NETGEN_3D::CancelCompute() -- 2.39.2