mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
BUG: avoid memory leak caused by IOobjectList::filterObjects (#1286)
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -622,11 +622,16 @@ Foam::label Foam::IOobjectList::filterClasses
|
|||||||
const bool pruning
|
const bool pruning
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
// This is like
|
||||||
// return HashPtrTable<IOobject>::filterValues
|
// return HashPtrTable<IOobject>::filterValues
|
||||||
// (
|
// (
|
||||||
// [&](const IOobject* io){ return pred(io->headerClassName()); },
|
// [&](const IOobject* io){ return pred(io->headerClassName()); },
|
||||||
// pruning
|
// pruning
|
||||||
// );
|
// );
|
||||||
|
// which is really
|
||||||
|
// return HashTable<IOobject*>::filterValues
|
||||||
|
//
|
||||||
|
// except that it does not leak
|
||||||
|
|
||||||
label changed = 0;
|
label changed = 0;
|
||||||
|
|
||||||
@ -654,7 +659,29 @@ Foam::label Foam::IOobjectList::filterObjects
|
|||||||
const bool pruning
|
const bool pruning
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return HashPtrTable<IOobject>::filterKeys(pred, pruning);
|
// This is like
|
||||||
|
// return HashPtrTable<IOobject>::filterKeys(pred, pruning);
|
||||||
|
// which is really
|
||||||
|
// return HashTable<IOobject*>::filterKeys(pred, pruning);
|
||||||
|
//
|
||||||
|
// except that it does not leak
|
||||||
|
|
||||||
|
label changed = 0;
|
||||||
|
|
||||||
|
for (iterator iter = begin(); iter != end(); ++iter)
|
||||||
|
{
|
||||||
|
// Matches? either prune (pruning) or keep (!pruning)
|
||||||
|
if
|
||||||
|
(
|
||||||
|
(pred(iter.key()) ? pruning : !pruning)
|
||||||
|
&& erase(iter)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
++changed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user