Fix possible memory leak in newPhase

If importPhase threw an exception, then the ThermoPhase object allocated here
would not be deleted. Switching to a smart pointer fixes this problem.
This commit is contained in:
Ray Speth 2015-09-10 17:43:06 -04:00
parent f335350c35
commit c2ba24c0c2

View file

@ -168,19 +168,19 @@ std::string eosTypeString(int ieos, int length)
ThermoPhase* newPhase(XML_Node& xmlphase)
{
string model = xmlphase.child("thermo")["model"];
ThermoPhase* t = newThermoPhase(model);
unique_ptr<ThermoPhase> t(newThermoPhase(model));
if (model == "singing cows") {
throw CanteraError("ThermoPhase::newPhase", "Cows don't sing");
} else if (model == "HMW") {
HMWSoln* p = dynamic_cast<HMWSoln*>(t);
HMWSoln* p = dynamic_cast<HMWSoln*>(t.get());
p->constructPhaseXML(xmlphase,"");
} else if (model == "IonsFromNeutralMolecule") {
IonsFromNeutralVPSSTP* p = dynamic_cast<IonsFromNeutralVPSSTP*>(t);
IonsFromNeutralVPSSTP* p = dynamic_cast<IonsFromNeutralVPSSTP*>(t.get());
p->constructPhaseXML(xmlphase,"");
} else {
importPhase(xmlphase, t);
importPhase(xmlphase, t.get());
}
return t;
return t.release();
}
ThermoPhase* newPhase(const std::string& infile, std::string id)