Don't leave partially initialized scorer on failure

This commit is contained in:
Reuben Morais 2020-05-03 15:39:07 +02:00
parent fdee05f321
commit 5deb8a2f7b

View File

@ -333,11 +333,12 @@ int
DS_EnableExternalScorer(ModelState* aCtx,
const char* aScorerPath)
{
aCtx->scorer_.reset(new Scorer());
int err = aCtx->scorer_->init(aScorerPath, aCtx->alphabet_);
std::unique_ptr<Scorer> scorer(new Scorer());
int err = scorer->init(aScorerPath, aCtx->alphabet_);
if (err != 0) {
return DS_ERR_INVALID_SCORER;
}
aCtx->scorer_ = std::move(scorer);
return DS_ERR_OK;
}