Skip to content

Commit c382987

Browse files
authored
Prevent possible race condition in NotifyAppControl (#54)
1 parent f6da9cc commit c382987

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

flutter/shell/platform/tizen/channels/app_control.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,13 @@ class AppControlManager {
120120
return instance;
121121
}
122122

123-
void Insert(std::unique_ptr<AppControl> app_control) {
124-
map_.insert({app_control->id(), std::move(app_control)});
123+
// Returns a pointer to the inserted element if successful, otherwise nullptr.
124+
AppControl* Insert(std::unique_ptr<AppControl> app_control) {
125+
auto iter = map_.emplace(app_control->id(), std::move(app_control));
126+
if (iter.second) {
127+
return iter.first->second.get();
128+
}
129+
return nullptr;
125130
}
126131

127132
void Remove(int32_t id) { map_.erase(id); }

flutter/shell/platform/tizen/channels/app_control_channel.cc

+8-3
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,18 @@ void AppControlChannel::NotifyAppControl(void* handle) {
5858
FT_LOG(Error) << "Could not create an instance of AppControl.";
5959
return;
6060
}
61+
AppControl* app_control_ptr =
62+
AppControlManager::GetInstance().Insert(std::move(app_control));
63+
if (!app_control_ptr) {
64+
FT_LOG(Error) << "The handle already exists.";
65+
return;
66+
}
6167
if (event_sink_) {
62-
SendAppControlEvent(app_control.get());
68+
SendAppControlEvent(app_control_ptr);
6369
} else {
6470
FT_LOG(Info) << "No event channel has been set up.";
65-
queue_.push(app_control.get());
71+
queue_.push(app_control_ptr);
6672
}
67-
AppControlManager::GetInstance().Insert(std::move(app_control));
6873
}
6974

7075
void AppControlChannel::HandleMethodCall(

0 commit comments

Comments
 (0)