void AccessController::CheckAsync(int fd, std::string sender_appid,
CompleteCallback callback) {
+ /* This is for handle freed issue */
+ auto tmp_handle = new std::shared_ptr<AccessController>(shared_from_this());
Job job([=]() -> Job::Type {
+ if ((*tmp_handle).use_count() == 1) {
+ delete tmp_handle;
+ return Job::Type::Continue;
+ }
+
int res = Check(fd, sender_appid);
auto* cbdata = new std::pair<CompleteCallback, int>(callback, res);
guint sid = g_idle_add(
delete cbdata;
}
+ delete tmp_handle;
return Job::Type::Continue;
});
using CompleteCallback = std::function<void(int)>;
-class AccessController {
+class AccessController : public std::enable_shared_from_this<AccessController> {
public:
explicit AccessController(bool trusted = false) : trusted_(trusted) {}
}
CynaraThread::~CynaraThread() {
- Job finish_job;
- Push(finish_job);
+ finished_ = true;
thread_.join();
}
void CynaraThread::ThreadRun() {
while (true) {
Job job = queue_.WaitAndPop();
- Job::Type ret = job.Do();
- if (ret == Job::Type::Finish)
+ if (finished_)
return;
+ Job::Type ret = job.Do();
}
}
#ifndef CYNARA_THREAD_HH_
#define CYNARA_THREAD_HH_
+#include <atomic>
#include <functional>
#include <shared-queue.hpp>
#include <thread>
Job Pop();
std::thread thread_;
+ std::atomic<bool> finished_ = false;
mutable tizen_base::SharedQueue<Job> queue_;
};
void Stub::AddPrivilege(const std::string& privilege) {
std::lock_guard<std::recursive_mutex> lock(GetMutex());
- access_controller_.AddPrivilege(privilege);
+ access_controller_->AddPrivilege(privilege);
}
void Stub::SetTrusted(const bool trusted) {
std::lock_guard<std::recursive_mutex> lock(GetMutex());
- access_controller_.SetTrusted(trusted);
+ access_controller_->SetTrusted(trusted);
}
std::shared_ptr<Port> Stub::FindPort(const std::string& instance) const {
_E("Reject request. %u:%u", cred->GetUid(), getuid());
res = -1;
} else {
- stub->access_controller_.CheckAsync(client->GetFd(), app_id,
+ stub->access_controller_->CheckAsync(client->GetFd(), app_id,
response_func);
return G_SOURCE_CONTINUE;
}
std::recursive_mutex& GetMutex() const;
private:
- AccessController access_controller_;
+ std::shared_ptr<AccessController> access_controller_ =
+ std::make_shared<AccessController>();
std::string port_name_;
std::list<std::shared_ptr<AcceptedPort>> ports_;
IEventListener* listener_ = nullptr;