Merge pull request #2448 from lissyx/fix-ctc-leak
Use std::shared_ptr instead of raw pointer for dictionary_
This commit is contained in:
commit
469ddd2cf7
@ -37,7 +37,8 @@ DecoderState::init(const Alphabet& alphabet,
|
|||||||
prefixes_.push_back(root);
|
prefixes_.push_back(root);
|
||||||
|
|
||||||
if (ext_scorer != nullptr && !ext_scorer->is_character_based()) {
|
if (ext_scorer != nullptr && !ext_scorer->is_character_based()) {
|
||||||
auto dict_ptr = ext_scorer->dictionary->Copy(true);
|
// no need for std::make_shared<>() since Copy() does 'new' behind the doors
|
||||||
|
auto dict_ptr = std::shared_ptr<PathTrie::FstType>(ext_scorer->dictionary->Copy(true));
|
||||||
root->set_dictionary(dict_ptr);
|
root->set_dictionary(dict_ptr);
|
||||||
auto matcher = std::make_shared<fst::SortedMatcher<PathTrie::FstType>>(*dict_ptr, fst::MATCH_INPUT);
|
auto matcher = std::make_shared<fst::SortedMatcher<PathTrie::FstType>>(*dict_ptr, fst::MATCH_INPUT);
|
||||||
root->set_matcher(matcher);
|
root->set_matcher(matcher);
|
||||||
|
@ -165,9 +165,9 @@ void PathTrie::remove() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PathTrie::set_dictionary(PathTrie::FstType* dictionary) {
|
void PathTrie::set_dictionary(std::shared_ptr<PathTrie::FstType> dictionary) {
|
||||||
dictionary_ = dictionary;
|
dictionary_ = dictionary;
|
||||||
dictionary_state_ = dictionary->Start();
|
dictionary_state_ = dictionary_->Start();
|
||||||
has_dictionary_ = true;
|
has_dictionary_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,4 +201,4 @@ void PathTrie::print(const Alphabet& a) {
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
printf("transcript:\t %s\n", tr.c_str());
|
printf("transcript:\t %s\n", tr.c_str());
|
||||||
}
|
}
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
@ -39,7 +39,7 @@ public:
|
|||||||
void iterate_to_vec(std::vector<PathTrie*>& output);
|
void iterate_to_vec(std::vector<PathTrie*>& output);
|
||||||
|
|
||||||
// set dictionary for FST
|
// set dictionary for FST
|
||||||
void set_dictionary(FstType* dictionary);
|
void set_dictionary(std::shared_ptr<FstType> dictionary);
|
||||||
|
|
||||||
void set_matcher(std::shared_ptr<fst::SortedMatcher<FstType>>);
|
void set_matcher(std::shared_ptr<fst::SortedMatcher<FstType>>);
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ private:
|
|||||||
std::vector<std::pair<int, PathTrie*>> children_;
|
std::vector<std::pair<int, PathTrie*>> children_;
|
||||||
|
|
||||||
// pointer to dictionary of FST
|
// pointer to dictionary of FST
|
||||||
FstType* dictionary_;
|
std::shared_ptr<FstType> dictionary_;
|
||||||
FstType::StateId dictionary_state_;
|
FstType::StateId dictionary_state_;
|
||||||
// true if finding ars in FST
|
// true if finding ars in FST
|
||||||
std::shared_ptr<fst::SortedMatcher<FstType>> matcher_;
|
std::shared_ptr<fst::SortedMatcher<FstType>> matcher_;
|
||||||
|
Loading…
Reference in New Issue
Block a user