TableBase copy constructor does not clear out interpolationWeights / no clone() functionality
Summary
TableBase might allocate an interpolator (interpolationWeights). interpolationWeights holds a reference to the set of input samples. When copying the TableBase it copies these interpolationWeights which now has a reference to some outside data. If this has gone out of scope the interpolator will access invalid data.
Steps to reproduce
Not trivial. Use copy construct on Table (or TableFile). Could not replicate it on e.g. damBreakWithObstacle (topo changes) with U set to uniformFixedValue with a table.
Example case
What is the current bug behaviour?
What is the expected correct behavior?
Relevant logs and/or images
Environment information
- OpenFOAM version : v2006
- Operating system : any
Possible fixes
Reset autoPtrs in copy constructor. This will trigger rebuilding the interpolator
template<class Type>
Foam::Function1Types::TableBase<Type>::TableBase(const TableBase<Type>& tbl)
:
Function1<Type>(tbl),
name_(tbl.name_),
bounding_(tbl.bounding_),
interpolationScheme_(tbl.interpolationScheme_),
table_(tbl.table_),
tableSamplesPtr_(nullptr),
interpolatorPtr_(nullptr)
{}