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:
parent
f335350c35
commit
c2ba24c0c2
1 changed files with 5 additions and 5 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue