Skip to content
Extraits de code Groupes Projets
Valider 548fbd81 rédigé par Thomas Goyne's avatar Thomas Goyne
Parcourir les fichiers

Fix a use-after-free when a SubsEditCtrl is destroyed while the thesaurus is loading

parent 4dc38447
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -42,7 +42,7 @@ Thesaurus::Thesaurus()
}
Thesaurus::~Thesaurus() {
// Explicit empty destructor needed for scoped_ptr with incomplete types
if (cancel_load) *cancel_load = true;
}
std::vector<Thesaurus::Entry> Thesaurus::Lookup(std::string word) {
......@@ -98,11 +98,18 @@ void Thesaurus::OnLanguageChanged() {
LOG_I("thesaurus/file") << "Using thesaurus: " << dat;
if (cancel_load) *cancel_load = true;
cancel_load = new bool{false};
auto cancel = cancel_load; // Needed to avoid capturing via `this`
agi::dispatch::Background().Async([=]{
try {
auto thes = agi::make_unique<agi::Thesaurus>(dat, idx);
agi::dispatch::Main().Sync([&thes, this]{
agi::dispatch::Main().Sync([&thes, cancel, this]{
if (!*cancel) {
impl = std::move(thes);
cancel_load = nullptr;
}
delete cancel;
});
}
catch (agi::Exception const& e) {
......
......@@ -39,6 +39,9 @@ class Thesaurus {
agi::signal::Connection dict_path_listener;
/// Thesaurus path change handler
void OnPathChanged();
bool *cancel_load = nullptr;
public:
/// A pair of a word and synonyms for that word
typedef std::pair<std::string, std::vector<std::string>> Entry;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter