void AccessController::CheckAsync(int fd, std::string sender_appid,
CompleteCallback callback) {
- /* This is for handle freed issue */
+ std::lock_guard<std::recursive_mutex> lock(GetMutex());
auto* tmp_handle = new std::shared_ptr<AccessController>(shared_from_this());
GMainContext* context = g_main_context_ref_thread_default();
Job job([=]() -> Job::Type {
+ std::lock_guard<std::recursive_mutex> job_lock(GetMutex());
if ((*tmp_handle).use_count() == 1) {
delete tmp_handle; // LCOV_EXCL_LINE
return Job::Type::Continue; // LCOV_EXCL_LINE
}
int res = Check(fd, sender_appid);
- auto* cbdata = new std::pair<CompleteCallback, int>(
- std::move(callback), res);
+ auto* cbdata = new std::tuple<CompleteCallback, int,
+ std::shared_ptr<AccessController>*>(
+ std::move(callback), res, tmp_handle);
auto* source = GLib::IdleAdd(
context,
[](gpointer data) -> gboolean {
- auto* cb_data = static_cast<std::pair<CompleteCallback, int>*>(data);
- auto [callback, res] = *cb_data;
+ auto* cb_data =
+ static_cast<std::tuple<CompleteCallback, int,
+ std::shared_ptr<AccessController>*>*>(
+ data);
+ auto [callback, res, ptr] = *cb_data;
+ std::lock_guard<std::recursive_mutex> cb_lock((*ptr)->GetMutex());
callback(res);
+ delete ptr;
delete cb_data;
return G_SOURCE_REMOVE;
},
g_source_set_priority(source, G_PRIORITY_DEFAULT);
g_main_context_unref(context);
- delete tmp_handle;
return Job::Type::Continue;
});
CynaraThread::GetInst().Push(std::move(job));
}
+std::recursive_mutex& AccessController::GetMutex() const { return mutex_; }
+
} // namespace internal
} // namespace rpc_port