Skip to content

Commit

Permalink
Merge pull request #175 from vincentcasseau/main
Browse files Browse the repository at this point in the history
All: fix mem leaks, part 3
  • Loading branch information
benoit128 authored Sep 11, 2024
2 parents 51c2d22 + 90432b1 commit 564ad8d
Show file tree
Hide file tree
Showing 26 changed files with 212 additions and 153 deletions.
11 changes: 6 additions & 5 deletions Cassiopee/Connector/Connector/blankIntersectingCells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
//=============================================================================
Expand Down Expand Up @@ -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;
}
//=====================================================================================
Expand Down
46 changes: 25 additions & 21 deletions Cassiopee/Connector/Connector/computeFrictionVelocityIBM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
47 changes: 41 additions & 6 deletions Cassiopee/Connector/Connector/setInterpDataForGhostCellsNGon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -88,23 +94,34 @@ 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();
E_Int* indPH = c->getIndPH();

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();
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 4 additions & 3 deletions Cassiopee/Connector/Connector/writeCoefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -781,6 +781,7 @@ PyObject* K_CONNECTOR::writeCoefs(PyObject* self, PyObject* args)
}
}
fclose(ptr_file);
delete [] file; delete [] strId;
}

/*-------------------------------*/
Expand Down
3 changes: 0 additions & 3 deletions Cassiopee/Converter/Converter/Converter1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Cassiopee/Converter/Converter/convertUnstruct2NGon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
31 changes: 18 additions & 13 deletions Cassiopee/Converter/Converter/setBCDataInGhostCells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ PyObject* K_CONVERTER::setBCDataInGhostCellsStruct(PyObject* self,
char* varString; char* eltType;
vector<E_Float*> fields; vector<E_Int> locs;
vector<E_Int*> 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;
Expand All @@ -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<FldArrayF*> listOfBCFieldsR;
vector<PyObject*> 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;
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Loading

0 comments on commit 564ad8d

Please sign in to comment.