Posted by
imachabeli on
Jul 19, 2011; 10:03pm
URL: http://quantlib.414.s1.nabble.com/Dangerous-constructor-in-Handle-class-tp13562.html
What is the purpose of this constructor for the handle class?
template <class T>
inline Handle<T>::Handle(T* p,bool registerAsObserver)
: link_(new Link(boost::shared_ptr<T>(p),registerAsObserver)) {}
If you create handle to something that you plan to delete later or
even worse to something that is on the stack (like I did by accident)
implicit boost pointer passed to Link will try to delete object that is not
supposed to be deleted.
In my case luckily CRT caught invalid heap address.
Anyway, I commented out this constructor and both Quantlib and test suite
compile and run. The only place this constructor is used us in
fdmbatesop.cpp (under experimental\finitedifference) and existing code can
be easily replaced with the following
FdmBatesOp::FdmBatesOp(
const boost::shared_ptr<FdmMesher>& mesher,
const boost::shared_ptr<BatesProcess>& batesProcess,
const FdmBoundaryConditionSet& bcSet,
const Size integroIntegrationOrder,
const boost::shared_ptr<FdmQuantoHelper>& quantoHelper)
: lambda_(batesProcess->lambda()),
delta_ (batesProcess->delta()),
nu_ (batesProcess->nu()),
m_(std::exp(nu_+0.5*delta_*delta_)-1.0),
gaussHermiteIntegration_(integroIntegrationOrder),
mesher_(mesher),
bcSet_(bcSet),
hestonOp_(new FdmHestonOp(mesher,
boost::shared_ptr<HestonProcess>(new HestonProcess(
batesProcess->riskFreeRate(),
Handle<YieldTermStructure>(
boost::shared_ptr<ZeroSpreadedTermStructure>(
new ZeroSpreadedTermStructure(
batesProcess->dividendYield(),
Handle<Quote>(boost::shared_ptr<Quote>(new
SimpleQuote(lambda_*m_))),
Continuous, NoFrequency,
batesProcess->dividendYield()->dayCounter()))),
batesProcess->s0(), batesProcess->v0(),
batesProcess->kappa(), batesProcess->theta(),
batesProcess->sigma(), batesProcess->rho())),
quantoHelper)) {
}
I just wrapped new in couple places inside a shared pointers
------------------------------------------------------------------------------
Magic Quadrant for Content-Aware Data Loss Prevention
Research study explores the data loss prevention market. Includes in-depth
analysis on the changes within the DLP market, and the criteria used to
evaluate the strengths and weaknesses of these DLP solutions.
http://www.accelacomm.com/jaw/sfnl/114/51385063/_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev