Don't leave partially initialized scorer on failure
This commit is contained in:
parent
fdee05f321
commit
5deb8a2f7b
@ -333,11 +333,12 @@ int
|
|||||||
DS_EnableExternalScorer(ModelState* aCtx,
|
DS_EnableExternalScorer(ModelState* aCtx,
|
||||||
const char* aScorerPath)
|
const char* aScorerPath)
|
||||||
{
|
{
|
||||||
aCtx->scorer_.reset(new Scorer());
|
std::unique_ptr<Scorer> scorer(new Scorer());
|
||||||
int err = aCtx->scorer_->init(aScorerPath, aCtx->alphabet_);
|
int err = scorer->init(aScorerPath, aCtx->alphabet_);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
return DS_ERR_INVALID_SCORER;
|
return DS_ERR_INVALID_SCORER;
|
||||||
}
|
}
|
||||||
|
aCtx->scorer_ = std::move(scorer);
|
||||||
return DS_ERR_OK;
|
return DS_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user