Commit a9aa9aee authored by Quentin Khan's avatar Quentin Khan

FFmaGenericLoader: fix memory leak in writeDistributionOfParticlesFromOctree

The `particle` pointer was allocated in the forEachLeaf callback but
freed outside. If there was more than one leaf, the pointer would not be
freed before the new allocation.
parent e98aba3b
......@@ -809,14 +809,14 @@ public:
* Fwriter.writeDistributionOfParticlesFromOctree(&tree, nbParticles);
* \endcode
*/
template <class Toctree>
template <class Toctree>
void writeDistributionOfParticlesFromOctree( Toctree *tree, const FSize N){
//
//
this->writeHeader(tree->getBoxCenter(),tree->getBoxWidth(), N, sizeof(FReal), 4 );
FReal * particles ;
tree->forEachLeaf([this]( typename Toctree::LeafClassType* leaf){
FReal * particles = nullptr;
FSize nbMaxParticlesInLeaf = 0 ;
tree->forEachLeaf([&]( typename Toctree::LeafClassType* leaf){
//
// Input
const FReal*const posX = leaf->getTargets()->getPositions()[0];
......@@ -836,11 +836,11 @@ template <class Toctree>
particles[j+2] = posZ[idxPart] ;
particles[j+3] = physicalValues[idxPart] ;
}
this-> writeArrayOfReal(particles, 4, nbParticlesInLeaf) ;
this->writeArrayOfReal(particles, 4, nbParticlesInLeaf) ;
});
delete [] particles ;
}
});
}
private:
......
Markdown is supported
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