From 90432b1aebbfc2ed247b771ad04f1e5f19062c70 Mon Sep 17 00:00:00 2001 From: vincentcasseau Date: Wed, 11 Sep 2024 10:18:16 +0200 Subject: [PATCH] All: fix mem leaks, part 3 --- .../Connector/blankIntersectingCells.cpp | 11 +++-- .../Connector/computeFrictionVelocityIBM.cpp | 46 +++++++++--------- .../setInterpDataForGhostCellsNGon.cpp | 47 ++++++++++++++++--- Cassiopee/Connector/Connector/writeCoefs.cpp | 7 +-- Cassiopee/Converter/Converter/Converter1.cpp | 3 -- .../Converter/convertUnstruct2NGon.cpp | 1 + .../Converter/setBCDataInGhostCells.cpp | 31 +++++++----- .../Generator/Generator/closeBorders.cpp | 40 ++++++---------- .../Generator/computeCellPlanarity.cpp | 3 +- Cassiopee/Generator/Generator/gapfixer.cpp | 30 ++++++------ Cassiopee/Generator/Generator/mmgs.cpp | 1 + Cassiopee/Generator/Generator/pointedHat.cpp | 2 +- .../Generator/Generator/selectInsideElts.cpp | 5 ++ Cassiopee/Generator/Generator/stitchedHat.cpp | 3 +- .../Geom/Geom/volumeFromCrossSections.cpp | 22 +++++---- Cassiopee/Intersector/PolyMeshTools/utils.cpp | 2 + .../KCore/KCore/Nuga/include/GeomAlgo.cxx | 2 + Cassiopee/KCore/install | 5 ++ Cassiopee/Post/Post/Stream/StreamSurf.cpp | 41 ++++++++-------- Cassiopee/Post/Post/selectInteriorFaces.cpp | 5 +- Cassiopee/Post/Post/zipper.cpp | 21 +++------ .../RigidMotion/RigidMotion/rotorMotion.cpp | 2 +- Cassiopee/Transform/Transform/cart2Cyl.cpp | 10 ++-- Cassiopee/Transform/Transform/cyl2Cart.cpp | 13 +++-- .../Transform/Transform/reorderAllUnstr.cpp | 10 ++-- .../Transform/Transform/splitConnexity.cpp | 2 +- 26 files changed, 212 insertions(+), 153 deletions(-) diff --git a/Cassiopee/Connector/Connector/blankIntersectingCells.cpp b/Cassiopee/Connector/Connector/blankIntersectingCells.cpp index 922bb2f60..1d084eaa5 100644 --- a/Cassiopee/Connector/Connector/blankIntersectingCells.cpp +++ b/Cassiopee/Connector/Connector/blankIntersectingCells.cpp @@ -567,8 +567,8 @@ E_Int K_CONNECTOR::blankIntersectingCellsPenta( } } } - for (E_Int v = 0; v < nfacettes; v++) - delete listFacettes[v]; + for (E_Int v = 0; v < nfacettes; v++) { delete listFacettes[v]; delete boxes[v]; } + delete bbtree; return 1; } @@ -813,8 +813,8 @@ E_Int K_CONNECTOR::blankIntersectingCellsHexa( } } } - for (E_Int v = 0; v < nfacettes; v++) - delete listFacettes[v]; + for (E_Int v = 0; v < nfacettes; v++) { delete listFacettes[v]; delete boxes[v]; } + delete bbtree; return 1; } //============================================================================= @@ -1029,7 +1029,8 @@ E_Int K_CONNECTOR::blankIntersectingCellsStruct( } } } - for (E_Int v = 0; v < nfacettes; v++) delete listFacettes[v]; + for (E_Int v = 0; v < nfacettes; v++) { delete listFacettes[v]; delete boxes[v]; } + delete bbtree; return 1; } //===================================================================================== diff --git a/Cassiopee/Connector/Connector/computeFrictionVelocityIBM.cpp b/Cassiopee/Connector/Connector/computeFrictionVelocityIBM.cpp index 7bc7f36ce..e048524e3 100644 --- a/Cassiopee/Connector/Connector/computeFrictionVelocityIBM.cpp +++ b/Cassiopee/Connector/Connector/computeFrictionVelocityIBM.cpp @@ -82,7 +82,8 @@ PyObject* K_CONNECTOR::_computeFrictionVelocityIBM(PyObject* self, PyObject* arg { PyErr_SetString(PyExc_TypeError, "computeFrictionVelocityIBM: Some required quantities cannot be extracted from zone."); - RELEASESHAREDZ(hook, varString, eltType); + if (res == 2) delete [] eltType; + RELEASESHAREDZ(hook, varString, (char*)NULL); return NULL; } @@ -107,26 +108,29 @@ PyObject* K_CONNECTOR::_computeFrictionVelocityIBM(PyObject* self, PyObject* arg FldArrayF aa_vec(npts), uext_vec(npts), nutcible_vec(npts); FldArrayF ut_vec(npts), vt_vec(npts), wt_vec(npts), mu_vec(npts), alpha_vec(npts), utauv_vec(npts); - for (E_Int noind = 0; noind < npts; noind++) - { - roext = densPtr[noind]; // Densite du point interpole. - pext = pressPtr[noind]; // Pression du point interpole. - muext = viscPtr[noind]; // Viscosite du point interpole. - // vitesse du pt ext - u = uPtr[noind]; - v = vPtr[noind]; - w = wPtr[noind]; -# include "IBC/commonMuskerLaw_init_constantVars.h" - // out= utau et err - } - // Newton pour utau -# include "IBC/commonMuskerLaw_Newton.h" - // Compute the correct yplus - for (E_Int noind = 0; noind < npts; noind++) - { - yplus_vec[noind] = aa_vec[noind]*utau_vec[noind]; - } - RELEASESHAREDZ(hook, (char*)NULL, (char*)NULL); + for (E_Int noind = 0; noind < npts; noind++) + { + roext = densPtr[noind]; // Densite du point interpole. + pext = pressPtr[noind]; // Pression du point interpole. + muext = viscPtr[noind]; // Viscosite du point interpole. + // vitesse du pt ext + u = uPtr[noind]; + v = vPtr[noind]; + w = wPtr[noind]; + # include "IBC/commonMuskerLaw_init_constantVars.h" + // out= utau et err + } + + // Newton pour utau + # include "IBC/commonMuskerLaw_Newton.h" + // Compute the correct yplus + for (E_Int noind = 0; noind < npts; noind++) + { + yplus_vec[noind] = aa_vec[noind]*utau_vec[noind]; + } + + if (res == 2) delete [] eltType; + RELEASESHAREDZ(hook, varString, (char*)NULL); Py_INCREF(Py_None); return Py_None; } diff --git a/Cassiopee/Connector/Connector/setInterpDataForGhostCellsNGon.cpp b/Cassiopee/Connector/Connector/setInterpDataForGhostCellsNGon.cpp index ce9fd4fba..7ad5034b8 100644 --- a/Cassiopee/Connector/Connector/setInterpDataForGhostCellsNGon.cpp +++ b/Cassiopee/Connector/Connector/setInterpDataForGhostCellsNGon.cpp @@ -59,6 +59,7 @@ PyObject* K_CONNECTOR::setInterpDataForGCNGon(PyObject* self, PyObject* args) res = K_NUMPY::getFromNumpyArray(FLDonor, FLDonorI, true); if (res == 0) { + RELEASESHAREDN(FL, FLI); PyErr_SetString(PyExc_TypeError, "setInterpDataForGhostCells: 2nd arg is not a valid numpy array."); return NULL; @@ -69,6 +70,8 @@ PyObject* K_CONNECTOR::setInterpDataForGCNGon(PyObject* self, PyObject* args) res = K_NUMPY::getFromNumpyArray(rindElt, Intext, true); if (res == 0) { + RELEASESHAREDN(FL, FLI); + RELEASESHAREDN(FLDonor, FLDonorI); PyErr_SetString(PyExc_TypeError, "setInterpDataForGhostCells: 3nd arg is not a valid numpy array."); return NULL; @@ -79,6 +82,9 @@ PyObject* K_CONNECTOR::setInterpDataForGCNGon(PyObject* self, PyObject* args) res = K_NUMPY::getFromNumpyArray(rindEltDonor, IntextD, true); if (res == 0) { + RELEASESHAREDN(FL, FLI); + RELEASESHAREDN(FLDonor, FLDonorI); + RELEASESHAREDN(rindElt, Intext); PyErr_SetString(PyExc_TypeError, "setInterpDataForGhostCells: 4nd arg is not a valid numpy array."); return NULL; @@ -88,11 +94,16 @@ PyObject* K_CONNECTOR::setInterpDataForGCNGon(PyObject* self, PyObject* args) K_FLD::FldArrayF* f; K_FLD::FldArrayI* c; char* varString; char* eltType; E_Int ni,nj,nk; - res = K_ARRAY::getFromArray2(array, varString, f, ni, nj, nk, c, eltType); - if (res == 0 || res == 1 || strcmp(eltType, "NGON") != 0) + E_Int res1 = K_ARRAY::getFromArray2(array, varString, f, ni, nj, nk, c, eltType); + if (res1 == 0 || res1 == 1 || strcmp(eltType, "NGON") != 0) { + RELEASESHAREDN(FL, FLI); + RELEASESHAREDN(FLDonor, FLDonorI); + RELEASESHAREDN(rindElt, Intext); + RELEASESHAREDN(rindEltDonor, IntextD); + RELEASESHAREDB(res1, array, f, c); PyErr_SetString(PyExc_TypeError, - "setInterpDataForGhostCells: 5th arg must be a NGON array."); + "setInterpDataForGhostCells: 5th arg must be an NGON array."); return NULL; } E_Int* nface = c->getNFace(); @@ -100,11 +111,17 @@ PyObject* K_CONNECTOR::setInterpDataForGCNGon(PyObject* self, PyObject* args) K_FLD::FldArrayF* fd; K_FLD::FldArrayI* cd; char* varStringd; char* eltTyped; E_Int nid,njd,nkd; - res = K_ARRAY::getFromArray2(arrayDonor, varStringd, fd, nid, njd, nkd, cd, eltTyped); - if (res == 0 || res == 1 || strcmp(eltTyped, "NGON") != 0) + E_Int res2 = K_ARRAY::getFromArray2(arrayDonor, varStringd, fd, nid, njd, nkd, cd, eltTyped); + if (res2 == 0 || res2 == 1 || strcmp(eltTyped, "NGON") != 0) { + RELEASESHAREDN(FL, FLI); + RELEASESHAREDN(FLDonor, FLDonorI); + RELEASESHAREDN(rindElt, Intext); + RELEASESHAREDN(rindEltDonor, IntextD); + RELEASESHAREDB(res1, array, f, c); + RELEASESHAREDB(res2, arrayDonor, fd, cd); PyErr_SetString(PyExc_TypeError, - "setInterpDataForGhostCells: 6th arg must be a NGON array."); + "setInterpDataForGhostCells: 6th arg must be an NGON array."); return NULL; } E_Int* nfaceDonor = cd->getNFace(); @@ -114,6 +131,12 @@ PyObject* K_CONNECTOR::setInterpDataForGCNGon(PyObject* self, PyObject* args) res = K_NUMPY::getFromNumpyArray(PE, PEI, true); if (res == 0) { + RELEASESHAREDN(FL, FLI); + RELEASESHAREDN(FLDonor, FLDonorI); + RELEASESHAREDN(rindElt, Intext); + RELEASESHAREDN(rindEltDonor, IntextD); + RELEASESHAREDB(res1, array, f, c); + RELEASESHAREDB(res2, arrayDonor, fd, cd); PyErr_SetString(PyExc_TypeError, "setInterpDataForGhostCells: 7th arg is not a valid numpy array."); return NULL; @@ -124,6 +147,13 @@ PyObject* K_CONNECTOR::setInterpDataForGCNGon(PyObject* self, PyObject* args) res = K_NUMPY::getFromNumpyArray(PEDonor, PEDonorI, true); if (res == 0) { + RELEASESHAREDN(FL, FLI); + RELEASESHAREDN(FLDonor, FLDonorI); + RELEASESHAREDN(rindElt, Intext); + RELEASESHAREDN(rindEltDonor, IntextD); + RELEASESHAREDN(PE, PEI); + RELEASESHAREDB(res1, array, f, c); + RELEASESHAREDB(res2, arrayDonor, fd, cd); PyErr_SetString(PyExc_TypeError, "setInterpDataForGhostCells: 8th arg is not a valid numpy array."); return NULL; @@ -207,10 +237,15 @@ PyObject* K_CONNECTOR::setInterpDataForGCNGon(PyObject* self, PyObject* args) } //printf("FIN RAC \n"); + // Libere la memoire RELEASESHAREDN(FL, FLI); RELEASESHAREDN(FLDonor, FLDonorI); + RELEASESHAREDN(rindElt, Intext); + RELEASESHAREDN(rindEltDonor, IntextD); RELEASESHAREDN(PE, PEI); RELEASESHAREDN(PEDonor, PEDonorI); + RELEASESHAREDB(res1, array, f, c); + RELEASESHAREDB(res2, arrayDonor, fd, cd); // Remet la map a plat E_Int size = map.size(); diff --git a/Cassiopee/Connector/Connector/writeCoefs.cpp b/Cassiopee/Connector/Connector/writeCoefs.cpp index 0b74f4a40..e74db5df2 100644 --- a/Cassiopee/Connector/Connector/writeCoefs.cpp +++ b/Cassiopee/Connector/Connector/writeCoefs.cpp @@ -591,7 +591,6 @@ PyObject* K_CONNECTOR::writeCoefs(PyObject* self, PyObject* args) // Parcours des zones d interpolation for (E_Int noz = 0; noz < nzones; noz++) { - // Id du bloc donneur E_Int BlockDonorId = noz; @@ -664,13 +663,14 @@ PyObject* K_CONNECTOR::writeCoefs(PyObject* self, PyObject* args) fprintf(ptr_file, SF_D_ " ", cellNgc[np]); } fclose(ptr_file); + delete [] file; delete [] strId; } // 1- Fichier d'interpolations // Ouverture du fichier FILE* ptr_file = NULL; char* file = new char[K_ARRAY::VARSTRINGLENGTH]; - strcpy(file,PrefixFile); + strcpy(file, PrefixFile); char* strId = new char[K_ARRAY::VARSTRINGLENGTH]; #if defined E_DOUBLEINT #if defined _WIN32 @@ -681,7 +681,7 @@ PyObject* K_CONNECTOR::writeCoefs(PyObject* self, PyObject* args) #else sprintf(strId,"%04d",BlockDonorId); #endif - strcat(file,strId); + strcat(file, strId); if (isEX) strcat(file,"_Int"); ptr_file = fopen(file, "w"); printf("Open file %s\n",file);fflush(stdout); @@ -781,6 +781,7 @@ PyObject* K_CONNECTOR::writeCoefs(PyObject* self, PyObject* args) } } fclose(ptr_file); + delete [] file; delete [] strId; } /*-------------------------------*/ diff --git a/Cassiopee/Converter/Converter/Converter1.cpp b/Cassiopee/Converter/Converter/Converter1.cpp index e23b2256f..8b1884d4d 100644 --- a/Cassiopee/Converter/Converter/Converter1.cpp +++ b/Cassiopee/Converter/Converter/Converter1.cpp @@ -973,11 +973,8 @@ PyObject* K_CONVERTER::convertArrays2File(PyObject* self, PyObject* args) // Deleting fields for (size_t i = 0; i < fieldc.size(); i++) RELEASESHAREDS(tplc[i], fieldc[i]); - for (size_t i = 0; i < fieldu.size(); i++) - { RELEASESHAREDU(tplu[i], fieldu[i], connectu[i]); - } Py_INCREF(Py_None); return Py_None; diff --git a/Cassiopee/Converter/Converter/convertUnstruct2NGon.cpp b/Cassiopee/Converter/Converter/convertUnstruct2NGon.cpp index 0e81b6f42..0c74b2598 100644 --- a/Cassiopee/Converter/Converter/convertUnstruct2NGon.cpp +++ b/Cassiopee/Converter/Converter/convertUnstruct2NGon.cpp @@ -80,6 +80,7 @@ PyObject* K_CONVERTER::convertUnstruct2NGon(PyObject* self, PyObject* args) { PyErr_SetString(PyExc_TypeError, "convertUnstruct2NGon: elt type of array (%d) is invalid."); + for (size_t v = 0; v < eltTypes.size(); v++) delete [] eltTypes[v]; RELEASESHAREDU(array, f, cnl); return NULL; } diff --git a/Cassiopee/Converter/Converter/setBCDataInGhostCells.cpp b/Cassiopee/Converter/Converter/setBCDataInGhostCells.cpp index 6d2f9bb77..8169fad5f 100644 --- a/Cassiopee/Converter/Converter/setBCDataInGhostCells.cpp +++ b/Cassiopee/Converter/Converter/setBCDataInGhostCells.cpp @@ -47,9 +47,9 @@ PyObject* K_CONVERTER::setBCDataInGhostCellsStruct(PyObject* self, char* varString; char* eltType; vector fields; vector locs; vector cn; - K_PYTREE::getFromZone(zone, 0, locI, varString, fields, locs, im0, jm0, km0, - cn, cnSize, cnNfld, eltType, hook, GridCoordinates, - FlowSolutionNodes, FlowSolutionCenters); + E_Int res = K_PYTREE::getFromZone(zone, 0, locI, varString, fields, locs, im0, jm0, km0, + cn, cnSize, cnNfld, eltType, hook, GridCoordinates, + FlowSolutionNodes, FlowSolutionCenters); E_Int dim = 3; if (km == 1) dim = 2; if (jm == 1) dim = 1; @@ -65,14 +65,15 @@ PyObject* K_CONVERTER::setBCDataInGhostCellsStruct(PyObject* self, { PyErr_SetString(PyExc_TypeError, "setBCDataInGhostCellsStruct: nb of bc ranges and bc datas are not equal."); - RELEASESHAREDZ(hook, (char*)NULL, (char*)NULL); + if (res == 2) delete [] eltType; + RELEASESHAREDZ(hook, varString, (char*)NULL); return NULL; } vector listOfBCFieldsR; vector listOfNumBCArrays; FldArrayI rangeBCs(nbc,6); - for (int v = 0; v < nbc; v++) + for (E_Int v = 0; v < nbc; v++) { PyObject* tpl = PyList_GetItem(dataBC, v); FldArrayF* bcFieldR; @@ -84,8 +85,9 @@ PyObject* K_CONVERTER::setBCDataInGhostCellsStruct(PyObject* self, { PyErr_SetString(PyExc_TypeError, "setBCDataInGhostCellsStruct: each bcrange must be a list."); - RELEASESHAREDZ(hook, (char*)NULL, (char*)NULL); - for (std::size_t no = 0; no < listOfBCFieldsR.size(); no++) + if (res == 2) delete [] eltType; + RELEASESHAREDZ(hook, varString, (char*)NULL); + for (size_t no = 0; no < listOfBCFieldsR.size(); no++) RELEASESHAREDN(listOfNumBCArrays[no], listOfBCFieldsR[no]); return NULL; } @@ -94,8 +96,9 @@ PyObject* K_CONVERTER::setBCDataInGhostCellsStruct(PyObject* self, { PyErr_SetString(PyExc_TypeError, "setBCDataInGhostCellsStruct: window must be [imin,imax,jmin,jmax,kmin,kmax]."); - RELEASESHAREDZ(hook, (char*)NULL, (char*)NULL); - for (std::size_t no = 0; no < listOfBCFieldsR.size(); no++) + if (res == 2) delete [] eltType; + RELEASESHAREDZ(hook, varString, (char*)NULL); + for (size_t no = 0; no < listOfBCFieldsR.size(); no++) RELEASESHAREDN(listOfNumBCArrays[no], listOfBCFieldsR[no]); return NULL; } @@ -120,8 +123,9 @@ PyObject* K_CONVERTER::setBCDataInGhostCellsStruct(PyObject* self, { PyErr_SetString(PyExc_TypeError, "setBCDataInGhostCellsStruct: variable not found in zone."); - RELEASESHAREDZ(hook, (char*)NULL, (char*)NULL); - for (std::size_t no = 0; no < listOfBCFieldsR.size(); no++) + if (res == 2) delete [] eltType; + RELEASESHAREDZ(hook, varString, (char*)NULL); + for (size_t no = 0; no < listOfBCFieldsR.size(); no++) RELEASESHAREDN(listOfNumBCArrays[no], listOfBCFieldsR[no]); return NULL; } @@ -301,9 +305,10 @@ PyObject* K_CONVERTER::setBCDataInGhostCellsStruct(PyObject* self, } } } - for (std::size_t no = 0; no < listOfBCFieldsR.size(); no++) + for (size_t no = 0; no < listOfBCFieldsR.size(); no++) RELEASESHAREDN(listOfNumBCArrays[no], listOfBCFieldsR[no]); - RELEASESHAREDZ(hook, (char*)NULL, (char*)NULL); + if (res == 2) delete [] eltType; + RELEASESHAREDZ(hook, varString, (char*)NULL); Py_INCREF(Py_None); return Py_None; } diff --git a/Cassiopee/Generator/Generator/closeBorders.cpp b/Cassiopee/Generator/Generator/closeBorders.cpp index ca4762304..c615bcdf5 100644 --- a/Cassiopee/Generator/Generator/closeBorders.cpp +++ b/Cassiopee/Generator/Generator/closeBorders.cpp @@ -123,19 +123,12 @@ PyObject* K_GENERATOR::closeBorders(PyObject* self, PyObject* args) { PyErr_SetString(PyExc_TypeError, "closeBorders: invalid list of arrays for exterior faces."); - size = structF.size(); - for (E_Int v = 0; v < size; v++) delete structF[v]; - size = unstrF.size(); - for (E_Int v = 0; v < size; v++) delete unstrF[v]; - size = cnt.size(); - for (E_Int v = 0; v < size; v++) delete cnt[v]; - - size = structEF.size(); - for (E_Int v = 0; v < size; v++) delete structEF[v]; - size = unstrEF.size(); - for (E_Int v = 0; v < size; v++) delete unstrEF[v]; - size = cne.size(); - for (E_Int v = 0; v < size; v++) delete cne[v]; + for (size_t v = 0; v < structF.size(); v++) delete structF[v]; + for (size_t v = 0; v < unstrF.size(); v++) delete unstrF[v]; + for (size_t v = 0; v < cnt.size(); v++) delete cnt[v]; + for (size_t v = 0; v < structEF.size(); v++) delete structEF[v]; + for (size_t v = 0; v < unstrEF.size(); v++) delete unstrEF[v]; + for (size_t v = 0; v < cne.size(); v++) delete cne[v]; return NULL; } @@ -156,16 +149,13 @@ PyObject* K_GENERATOR::closeBorders(PyObject* self, PyObject* args) posze.push_back(posz+1); } closeAllUnstructuredMeshes(unstrF, cnt, posxu, posyu, poszu, - unstrEF, cne, posxe, posye, posze, - eps); + unstrEF, cne, posxe, posye, posze, + eps); //cleaning - size = structEF.size(); - for (E_Int v = 0; v < size; v++) delete structEF[v]; - size = unstrEF.size(); - for (E_Int v = 0; v < size; v++) delete unstrEF[v]; - size = cne.size(); - for (E_Int v = 0; v < size; v++) delete cne[v]; + for (size_t v = 0; v < structEF.size(); v++) delete structEF[v]; + for (size_t v = 0; v < unstrEF.size(); v++) delete unstrEF[v]; + for (size_t v = 0; v < cne.size(); v++) delete cne[v]; } }// unstructured @@ -176,7 +166,7 @@ PyObject* K_GENERATOR::closeBorders(PyObject* self, PyObject* args) { FldArrayF& f0 = *structF[v]; tpl = K_ARRAY::buildArray(f0, structVarString[v], nit[v], njt[v], nkt[v]); - delete &f0; + delete structF[v]; PyList_Append(l, tpl); Py_DECREF(tpl); } @@ -186,10 +176,10 @@ PyObject* K_GENERATOR::closeBorders(PyObject* self, PyObject* args) FldArrayF& f0 = *unstrF[v]; tpl = K_ARRAY::buildArray(f0, unstrVarString[v], *cnt[v], -1, eltType[v], false); - delete &f0; delete cnt[v]; + delete unstrF[v]; delete cnt[v]; PyList_Append(l, tpl); Py_DECREF(tpl); - } + } return l; } @@ -580,4 +570,4 @@ void K_GENERATOR::closeAllStructuredMeshes( } } // tous les pts -} \ No newline at end of file +} diff --git a/Cassiopee/Generator/Generator/computeCellPlanarity.cpp b/Cassiopee/Generator/Generator/computeCellPlanarity.cpp index 619e7ffb3..3f4427d37 100644 --- a/Cassiopee/Generator/Generator/computeCellPlanarity.cpp +++ b/Cassiopee/Generator/Generator/computeCellPlanarity.cpp @@ -97,7 +97,7 @@ K_GENERATOR::computeCellPlanarity( PyObject* self, PyObject* args ) *dist, ni1, nj1, nk1); PyObject* tpl = K_ARRAY::buildArray(*dist, "dist", ni1, nj1, nk1); - delete dist; + delete dist; delete f; return tpl; } else @@ -121,6 +121,7 @@ K_GENERATOR::computeCellPlanarity( PyObject* self, PyObject* args ) PyObject* tpl = K_ARRAY::buildArray(*dist, "dist", *connect, -1, eltType, true); delete dist; delete connect; + delete f; delete cn; return tpl; } } diff --git a/Cassiopee/Generator/Generator/gapfixer.cpp b/Cassiopee/Generator/Generator/gapfixer.cpp index 85e711580..19ca03d37 100644 --- a/Cassiopee/Generator/Generator/gapfixer.cpp +++ b/Cassiopee/Generator/Generator/gapfixer.cpp @@ -51,13 +51,13 @@ PyObject* K_GENERATOR::gapfixer(PyObject* self, PyObject* args) { if (ni != 1 && nj != 1 && nk != 1) { - delete fB0; + delete fB0; delete cn1; // always delete cn1 because DynArray PyErr_SetString(PyExc_TypeError, "gapfixer: array must define a plane."); return NULL; } } - if (res1 == 2) + else if (res1 == 2) { if (strcmp(eltType, "TRI") != 0 && strcmp(eltType, "QUAD") != 0 && @@ -78,8 +78,7 @@ PyObject* K_GENERATOR::gapfixer(PyObject* self, PyObject* args) if ((posx == -1) || (posy == -1) || (posz == -1)) { - delete fB0; - if (res1 == 2) delete cn1; + delete fB0; delete cn1; // always delete cn1 because DynArray PyErr_SetString(PyExc_TypeError, "gapfixer: can't find coordinates in array."); return NULL; @@ -91,6 +90,8 @@ PyObject* K_GENERATOR::gapfixer(PyObject* self, PyObject* args) if (res2 != 1) { + delete fB0; delete cn1; + if (res2 == 2) { delete fC; delete cn2; } PyErr_SetString(PyExc_TypeError, "gapfixer: invalid array. Must be structured."); return NULL; @@ -101,8 +102,7 @@ PyObject* K_GENERATOR::gapfixer(PyObject* self, PyObject* args) if (not_a_surface) { - delete fC; - if (res2 == 2) delete cn2; + delete fB0; delete cn1; delete fC; delete cn2; PyErr_SetString(PyExc_TypeError, "gapfixer: array must define a surface."); return NULL; @@ -117,8 +117,7 @@ PyObject* K_GENERATOR::gapfixer(PyObject* self, PyObject* args) if ((posx == -1) || (posy == -1) || (posz == -1)) { - delete fC; - if (res2 == 2) delete cn2; + delete fB0; delete cn1; delete fC; delete cn2; PyErr_SetString(PyExc_TypeError, "gapfixer: can't find coordinates in array."); return NULL; @@ -139,12 +138,14 @@ PyObject* K_GENERATOR::gapfixer(PyObject* self, PyObject* args) if ((posx == -1) || (posy == -1) || (posz == -1)) { - delete fHP; + delete fB0; delete cn1; delete fC; delete cn2; + delete fHP; delete cndum; PyErr_SetString(PyExc_TypeError, "gapfixer: can't find coordinates in the hard points array."); return NULL; } } + delete cndum; // always delete because DynArray } K_FLD::FloatArray &posB0 = *fB0; @@ -156,17 +157,18 @@ PyObject* K_GENERATOR::gapfixer(PyObject* self, PyObject* args) if (err) { + delete fB0; delete cn1; delete fC; delete cn2; + delete fHP; PyErr_SetString(PyExc_TypeError, - "gapfixer: failed to proceed."); + "gapfixer: failed to proceed."); return NULL; } PyObject* tpl = K_ARRAY::buildArray(posG, varString, connectG, -1, "TRI", false); - delete fB0; - delete fC; - if (res1 == 2) delete cn1; - if (res2 == 2) delete cn2; + delete fB0; delete fC; delete fHP; + //if (res1 == 2) delete cn1; // only for FldArray + delete cn1; delete cn2; // always delete because DynArray (see getFromArrayDyn) return tpl; } diff --git a/Cassiopee/Generator/Generator/mmgs.cpp b/Cassiopee/Generator/Generator/mmgs.cpp index b9e550566..31d39fc23 100644 --- a/Cassiopee/Generator/Generator/mmgs.cpp +++ b/Cassiopee/Generator/Generator/mmgs.cpp @@ -411,6 +411,7 @@ PyObject* K_GENERATOR::mmgs(PyObject* self, PyObject* args) //_MMGS_RETURN_AND_FREE(mesh, met, ier); RELEASESHAREDB(res, array, f, cn); + RELEASESHAREDU(o, fo, co); return o; } diff --git a/Cassiopee/Generator/Generator/pointedHat.cpp b/Cassiopee/Generator/Generator/pointedHat.cpp index c4b50327c..69b736e48 100644 --- a/Cassiopee/Generator/Generator/pointedHat.cpp +++ b/Cassiopee/Generator/Generator/pointedHat.cpp @@ -87,6 +87,6 @@ PyObject* K_GENERATOR::pointedHat(PyObject* self, PyObject* args) E_Int im2 = im; E_Int jm2 = jm; E_Int km2 = 2; if (jm == 1) {jm2 = 2; km2 = 1;} PyObject* tpl = K_ARRAY::buildArray(*sol, "x,y,z", im2, jm2, km2); - delete sol; + delete f; delete sol; return tpl; } diff --git a/Cassiopee/Generator/Generator/selectInsideElts.cpp b/Cassiopee/Generator/Generator/selectInsideElts.cpp index df44879a5..4a6f6dffd 100644 --- a/Cassiopee/Generator/Generator/selectInsideElts.cpp +++ b/Cassiopee/Generator/Generator/selectInsideElts.cpp @@ -223,6 +223,11 @@ PyObject* K_GENERATOR::selectInsideElts(PyObject* self, PyObject* args) // sortie PyObject* tpl; tpl = K_ARRAY::buildArray(*f, varString, connectp, -1, eltType); + + for (size_t i = 0; i < cnt.size(); i++) delete cnt[i]; + //for (size_t i = 0; i < objut.size(); i++) Py_DECREF(objut[i]); + for (E_Int i = 0; i < ncurves; i++) delete curves[i]; delete f; delete cn; delete connect; + return tpl; } diff --git a/Cassiopee/Generator/Generator/stitchedHat.cpp b/Cassiopee/Generator/Generator/stitchedHat.cpp index b36c823f4..2fb257d5b 100644 --- a/Cassiopee/Generator/Generator/stitchedHat.cpp +++ b/Cassiopee/Generator/Generator/stitchedHat.cpp @@ -186,7 +186,8 @@ PyObject* K_GENERATOR::stitchedHat(PyObject* self, PyObject* args) E_Int im2 = im; E_Int jm2 = jm; E_Int km2 = 2; if (jm == 1) {jm2 = 2; km2 = 1;} PyObject* tpl = K_ARRAY::buildArray(*sol, "x,y,z", im2, jm2, km2); - delete sol; + delete f; delete sol; + delete [] hanging; return tpl; } diff --git a/Cassiopee/Geom/Geom/volumeFromCrossSections.cpp b/Cassiopee/Geom/Geom/volumeFromCrossSections.cpp index 88900a0ae..3106e115e 100644 --- a/Cassiopee/Geom/Geom/volumeFromCrossSections.cpp +++ b/Cassiopee/Geom/Geom/volumeFromCrossSections.cpp @@ -56,7 +56,7 @@ PyObject* K_GEOM::volumeFromCrossSections(PyObject* self, E_Int posxc1, posyc1, poszc1; E_Int posxc2, posyc2, poszc2; - if ( resc1 == 2 && resc2 == 2) + if (resc1 == 2 && resc2 == 2) { if ( strcmp(eltTypec1, "BAR") != 0 || strcmp(eltTypec2, "BAR") != 0) { @@ -121,9 +121,10 @@ PyObject* K_GEOM::volumeFromCrossSections(PyObject* self, // Check args if (res1 != 2 || strcmp(eltType1, "TRI") != 0) { - if (res1 == 1) delete f1; - if (res2 >= 1) delete f2; - if (res2 == 2) delete cn2; + if (res1 == 1) delete f1; + else if (res1 == 2) { delete f1; delete cn1; } + if (res2 == 1) delete f2; + else if (res2 == 2) { delete f2; delete cn2; } delete fc1; delete fc2; delete cnpoly1; delete cnpoly2; PyErr_SetString(PyExc_ValueError, @@ -133,7 +134,8 @@ PyObject* K_GEOM::volumeFromCrossSections(PyObject* self, if (res2 != 2 || strcmp(eltType2, "TRI") != 0) { delete f1; delete cn1; - if (res2 >= 1) delete f2; + if (res2 == 1) delete f2; + else if (res2 == 2) { delete f2; delete cn2; } delete fc1; delete fc2; delete cnpoly1; delete cnpoly2; PyErr_SetString(PyExc_ValueError, @@ -146,8 +148,7 @@ PyObject* K_GEOM::volumeFromCrossSections(PyObject* self, E_Int posz1 = K_ARRAY::isCoordinateZPresent( varString1); if (posx1 == -1 || posy1 == -1 || posz1 == -1) { - delete f1; - if (res1 == 2) delete cn1; + delete f1; delete cn1; delete f2; delete cn2; delete fc1; delete fc2; delete cnpoly1; delete cnpoly2; PyErr_SetString(PyExc_TypeError, @@ -161,8 +162,7 @@ PyObject* K_GEOM::volumeFromCrossSections(PyObject* self, E_Int posz2 = K_ARRAY::isCoordinateZPresent( varString2 ); if (posx2 == -1 || posy2 == -1 || posz2 == -1) { - delete f2; - if (res2 == 2) delete cn2; + delete f1; delete cn1; delete f2; delete cn2; delete fc1; delete fc2; delete cnpoly1; delete cnpoly2; PyErr_SetString(PyExc_TypeError, @@ -232,7 +232,9 @@ PyObject* K_GEOM::volumeFromCrossSections(PyObject* self, checkTetrahedra(type, cn, coord); PyObject* tpl = K_ARRAY::buildArray(coord, "x,y,z", cn, 4, "TETRA"); - delete &coord; + delete an; delete cni; + delete f1; delete cn1; delete f2; delete cn2; + delete fc1; delete fc2; delete cnpoly1; delete cnpoly2; return tpl; } diff --git a/Cassiopee/Intersector/PolyMeshTools/utils.cpp b/Cassiopee/Intersector/PolyMeshTools/utils.cpp index 6f4b198e2..a07dbd6db 100755 --- a/Cassiopee/Intersector/PolyMeshTools/utils.cpp +++ b/Cassiopee/Intersector/PolyMeshTools/utils.cpp @@ -1055,6 +1055,7 @@ PyObject* K_INTERSECTOR::checkCellsFlux(PyObject* self, PyObject* args) if (ngi.PGs.size() != cFE->getSize()) { std::cout << "le ParentElment ne correpsond pas au nb de pgs" << std::endl; + RELEASESHAREDN(PE, cFE); delete f; delete cn; return nullptr; } @@ -1137,6 +1138,7 @@ PyObject* K_INTERSECTOR::checkCellsFlux(PyObject* self, PyObject* args) PyList_Append(l, tpl); #endif + RELEASESHAREDN(PE, cFE); return l; } diff --git a/Cassiopee/KCore/KCore/Nuga/include/GeomAlgo.cxx b/Cassiopee/KCore/KCore/Nuga/include/GeomAlgo.cxx index 288baac42..09d20d039 100755 --- a/Cassiopee/KCore/KCore/Nuga/include/GeomAlgo.cxx +++ b/Cassiopee/KCore/KCore/Nuga/include/GeomAlgo.cxx @@ -343,6 +343,8 @@ inline void GeomAlgo::reversi_chimera_skin if (orient[k] == -1) std::swap((*cnts[i])(1,k), (*cnts[i])(2,k)); } + + delete[] pool; } /// diff --git a/Cassiopee/KCore/install b/Cassiopee/KCore/install index 9e1bd0462..316c8028e 100755 --- a/Cassiopee/KCore/install +++ b/Cassiopee/KCore/install @@ -99,6 +99,11 @@ cp test/compareSessionLogs "$INSTALLPATH" # LSAN: Ajoute un fichier pour supprimer certaines fuites memoire du log cat > "$INSTALLPATH"/asan.supp <left == NULL) tleft = front[v]; if (front[v]->right == NULL) tright = front[v]; } if (tleft == NULL || tright == NULL) { - unsigned int last = front.size()-1; + size_t last = front.size()-1; tleft = front[0]; tright = front[last]; front[0]->left = NULL; front[last]->right = NULL; } @@ -402,12 +402,15 @@ PyObject* K_POST::compStreamSurf(PyObject* self, PyObject* args) front.clear(); RELEASESHAREDU(arrayBAR,f, cnBAR); - for (unsigned int nos = 0; nos < objs0.size(); nos++) + for (size_t nos = 0; nos < objs0.size(); nos++) RELEASESHAREDS(objs0[nos], structF[nos]); - for (unsigned int nos = 0; nos < obju0.size(); nos++) + for (size_t nos = 0; nos < obju0.size(); nos++) RELEASESHAREDU(obju0[nos], unstrF[nos], cnt[nos]); - for (unsigned int nos = 0; nos < structInterpDatas1.size(); nos++) + for (size_t nos = 0; nos < structInterpDatas1.size(); nos++) delete structInterpDatas1[nos]; + for (size_t nos = 0; nos < unstrInterpDatas2.size(); nos++) + delete unstrInterpDatas2[nos]; + return tpl; } //============================================================================= diff --git a/Cassiopee/Post/Post/selectInteriorFaces.cpp b/Cassiopee/Post/Post/selectInteriorFaces.cpp index 07915c2e3..014c279ef 100644 --- a/Cassiopee/Post/Post/selectInteriorFaces.cpp +++ b/Cassiopee/Post/Post/selectInteriorFaces.cpp @@ -67,6 +67,8 @@ PyObject* K_POST::selectInteriorFaces(PyObject* self, PyObject* args) } else { + delete f; + if (res == 2) delete cnp; PyErr_SetString(PyExc_TypeError, "selectInteriorFaces: only for TRI and QUAD."); return NULL; @@ -175,6 +177,7 @@ PyObject* K_POST::selectInteriorFaces(PyObject* self, PyObject* args) // Build array PyObject* tpl; tpl = K_ARRAY::buildArray(*fnodes, varString, *connect, -1, "BAR"); - delete fnodes; delete connect; + delete f; delete fnodes; delete connect; + if (res == 2) delete cnp; return tpl; } diff --git a/Cassiopee/Post/Post/zipper.cpp b/Cassiopee/Post/Post/zipper.cpp index fb27c3ad6..c9212b80a 100644 --- a/Cassiopee/Post/Post/zipper.cpp +++ b/Cassiopee/Post/Post/zipper.cpp @@ -91,7 +91,7 @@ PyObject* K_POST::zipperF(PyObject* self, PyObject* args) { PyErr_SetString(PyExc_TypeError, "zipper: invalid list of arrays."); - for (unsigned int nos = 0; nos < objst.size(); nos++) + for (size_t nos = 0; nos < objst.size(); nos++) RELEASESHAREDS(objst[nos], structF[nos]); return NULL; } @@ -127,7 +127,7 @@ PyObject* K_POST::zipperF(PyObject* self, PyObject* args) { PyErr_SetString(PyExc_TypeError, "zipper: celln must be the last variable in all the arrays."); - for (unsigned int nos = 0; nos < objst.size(); nos++) + for (size_t nos = 0; nos < objst.size(); nos++) RELEASESHAREDS(objst[nos], structF[nos]); return NULL; } @@ -167,7 +167,7 @@ PyObject* K_POST::zipperF(PyObject* self, PyObject* args) printf("Warning: zipper: one array is empty. Skipped.\n"); } - for (unsigned int nos = 0; nos < objst.size(); nos++) + for (size_t nos = 0; nos < objst.size(); nos++) RELEASESHAREDS(objst[nos], structF[nos]); if (c == 0) { @@ -192,21 +192,14 @@ PyObject* K_POST::zipperF(PyObject* self, PyObject* args) // isZipped : retourne True si la paire de segments a ete triangulee FldArrayB isZipped(segPairs.size()); - zipInbetweenPairs(segPairs, - field, - triConnect, isZipped); + zipInbetweenPairs(segPairs, field, triConnect, isZipped); // Close remaining pockets closePockets(strings, segPairs, field, triConnect); - E_Int stringsSize = strings.size(); - for (E_Int v = 0; v < stringsSize; v++) - delete strings[v]; - strings.clear(); - E_Int segPairsSize = segPairs.size(); - for (E_Int v = 0; v < segPairsSize; v++) - delete segPairs[v]; - segPairs.clear(); + for (size_t v = 0; v < strings.size(); v++) delete strings[v]; + for (size_t v = 0; v < segPairs.size(); v++) delete segPairs[v]; + strings.clear(); segPairs.clear(); // Merge all zones in one vector idgT; diff --git a/Cassiopee/RigidMotion/RigidMotion/rotorMotion.cpp b/Cassiopee/RigidMotion/RigidMotion/rotorMotion.cpp index e6ae6e524..137f119cb 100644 --- a/Cassiopee/RigidMotion/RigidMotion/rotorMotion.cpp +++ b/Cassiopee/RigidMotion/RigidMotion/rotorMotion.cpp @@ -478,7 +478,7 @@ PyObject* K_RIGIDMOTION::_computeRotorMotionZ(PyObject* self, PyObject* args) } if (res == 2) delete [] eltType; - RELEASESHAREDZ(hookz, (char*)NULL, (char*)NULL); + RELEASESHAREDZ(hookz, varString, (char*)NULL); Py_INCREF(Py_None); return Py_None; } diff --git a/Cassiopee/Transform/Transform/cart2Cyl.cpp b/Cassiopee/Transform/Transform/cart2Cyl.cpp index 3afa1ca6c..39402ed38 100644 --- a/Cassiopee/Transform/Transform/cart2Cyl.cpp +++ b/Cassiopee/Transform/Transform/cart2Cyl.cpp @@ -126,7 +126,8 @@ PyObject* K_TRANSFORM::_cart2CylZ(PyObject* self, PyObject* args) E_Int posz = K_ARRAY::isCoordinateZPresent(varString); if (posx == -1 || posy == -1 || posz == -1) { - RELEASESHAREDZ(hook, (char*)NULL, (char*)NULL); + if (res == 2) delete [] eltType; + RELEASESHAREDZ(hook, varString, (char*)NULL); PyErr_SetString(PyExc_TypeError, "cart2Cyl: cannot find coordinates in zone."); return NULL; @@ -156,13 +157,14 @@ PyObject* K_TRANSFORM::_cart2CylZ(PyObject* self, PyObject* args) X0, Y0, Z0, ex, ey, ez, rt, thetat, im, jm, km, depth, thetaShift); if (ret == 1) { - RELEASESHAREDZ(hook, (char*)NULL, (char*)NULL); + if (res == 2) delete [] eltType; + RELEASESHAREDZ(hook, varString, (char*)NULL); PyErr_SetString(PyExc_TypeError, "cart2Cyl: axis must be canonical."); return NULL; } - delete [] eltType; - RELEASESHAREDZ(hook, (char*)NULL, (char*)NULL); + if (res == 2) delete [] eltType; + RELEASESHAREDZ(hook, varString, (char*)NULL); Py_INCREF(Py_None); return Py_None; } diff --git a/Cassiopee/Transform/Transform/cyl2Cart.cpp b/Cassiopee/Transform/Transform/cyl2Cart.cpp index b4d11e3c3..0b37a5c3d 100644 --- a/Cassiopee/Transform/Transform/cyl2Cart.cpp +++ b/Cassiopee/Transform/Transform/cyl2Cart.cpp @@ -110,7 +110,8 @@ PyObject* K_TRANSFORM::_cyl2CartZ(PyObject* self, PyObject* args) E_Float X0, Y0, Z0; E_Float ex, ey, ez; if (!PYPARSETUPLE_(args, O_ TRRR_ TRRR_ SSS_, - &zone, &X0, &Y0, &Z0, &ex, &ey, &ez, &GridCoordinates, &FlowSolutionNodes, &FlowSolutionCenters)) + &zone, &X0, &Y0, &Z0, &ex, &ey, &ez, &GridCoordinates, + &FlowSolutionNodes, &FlowSolutionCenters)) return NULL; vector hook; @@ -128,7 +129,8 @@ PyObject* K_TRANSFORM::_cyl2CartZ(PyObject* self, PyObject* args) E_Int posz = K_ARRAY::isCoordinateZPresent(varString); if (posx == -1 || posy == -1 || posz == -1) { - RELEASESHAREDZ(hook, (char*)NULL, (char*)NULL); + if (res == 2) delete [] eltType; + RELEASESHAREDZ(hook, varString, (char*)NULL); PyErr_SetString(PyExc_TypeError, "cyl2Cart: cannot find coordinates in zone."); return NULL; @@ -154,7 +156,8 @@ PyObject* K_TRANSFORM::_cyl2CartZ(PyObject* self, PyObject* args) } else { - RELEASESHAREDZ(hook, (char*)NULL, (char*)NULL); + if (res == 2) delete [] eltType; + RELEASESHAREDZ(hook, varString, (char*)NULL); PyErr_SetString(PyExc_TypeError, "cyl2Cart: axis must be x,y or z."); return NULL; @@ -175,8 +178,8 @@ PyObject* K_TRANSFORM::_cyl2CartZ(PyObject* self, PyObject* args) }//(y,z) dans le cas (X;R;Theta), (x,y) dans le cas (R,Theta,Z), (z,x) dans le cas (Theta,Y,R) } - delete [] eltType; - RELEASESHAREDZ(hook, (char*)NULL, (char*)NULL); + if (res == 2) delete [] eltType; + RELEASESHAREDZ(hook, varString, (char*)NULL); Py_INCREF(Py_None); return Py_None; } diff --git a/Cassiopee/Transform/Transform/reorderAllUnstr.cpp b/Cassiopee/Transform/Transform/reorderAllUnstr.cpp index 000fba10d..d6fcb1141 100644 --- a/Cassiopee/Transform/Transform/reorderAllUnstr.cpp +++ b/Cassiopee/Transform/Transform/reorderAllUnstr.cpp @@ -61,16 +61,16 @@ PyObject* K_TRANSFORM::reorderAllUnstr(PyObject* self, PyObject* args) E_Int posx, posy, posz; FloatArray* f; IntArray* cn; char* varString; char* eltType; - vector is_quad(nzone, false); + vector is_quad(nzone, false); // Extraction des infos pour chaque bloc - for (int i = 0; i < nzone; i++) + for (E_Int i = 0; i < nzone; i++) { E_Int nil, njl, nkl; PyObject* tpl = PyList_GetItem(listBlks, i); E_Int res = - K_ARRAY::getFromArray(tpl, varString, f, nil, njl, nkl,cn,eltType); + K_ARRAY::getFromArray(tpl, varString, f, nil, njl, nkl, cn, eltType); if (res != 2) { @@ -95,6 +95,7 @@ PyObject* K_TRANSFORM::reorderAllUnstr(PyObject* self, PyObject* args) if (posx == -1 || posy == -1 || posz == -1) { + delete f; delete cn; PyErr_SetString(PyExc_TypeError, "reorderAllUnstr: coordinates not found."); return NULL; @@ -117,8 +118,7 @@ PyObject* K_TRANSFORM::reorderAllUnstr(PyObject* self, PyObject* args) tcnt.pushBack(T, T+3); } } - else - tri_cnts[i]=cn; + else tri_cnts[i]=cn; //std::cout << "zone type is quad : " << is_quad[i] << std::endl; diff --git a/Cassiopee/Transform/Transform/splitConnexity.cpp b/Cassiopee/Transform/Transform/splitConnexity.cpp index 102da8eff..1e55be510 100644 --- a/Cassiopee/Transform/Transform/splitConnexity.cpp +++ b/Cassiopee/Transform/Transform/splitConnexity.cpp @@ -44,7 +44,7 @@ PyObject* K_TRANSFORM::splitConnexity(PyObject* self, PyObject* args) E_Int res = K_ARRAY::getFromArray(array, varString, f, im, jm, km, cn, eltType, true); - if (res != 2) + if (res != 1 && res != 2) { PyErr_SetString(PyExc_TypeError, "splitConnexity: unknown type of array.");