Prevent from undefined behaviour during destruction of channel users 59/137959/6
authorPiotr Sawicki <p.sawicki2@partner.samsung.com>
Mon, 10 Jul 2017 11:36:06 +0000 (13:36 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Wed, 12 Jul 2017 14:44:02 +0000 (14:44 +0000)
Change-Id: I07339e74068e066ec61a724b8a1ef6c2dd9670a0

src/client/impl/ApiInterfaceImpl.cpp
src/client/impl/ApiInterfaceImpl.h
src/notification-daemon/Logic.cpp
src/notification-daemon/Logic.h

index 393924e04c95ba65fba38c5b199844b2ffb5af88..ec96944cfe7ff91669367a90ba538c6381db8219 100644 (file)
@@ -68,8 +68,10 @@ namespace Client {
 
 ApiInterfaceImpl::ApiInterfaceImpl(const StatusCallbackClosure &statusClosure)
 : m_statusClosure(statusClosure)
-, m_channel(std::move(Protocol::ClientCallbacksPtr(new ClientCallbacks(this))))
 {
+    Protocol::ClientCallbacksPtr callbacks(new ClientCallbacks(this));
+    std::unique_ptr<Protocol::ClientChannel> channel(new Protocol::ClientChannel(std::move(callbacks)));
+    m_channel = std::move(channel);
 }
 
 ApiInterfaceImpl::~ApiInterfaceImpl()
@@ -80,11 +82,12 @@ ApiInterfaceImpl::~ApiInterfaceImpl()
     }
 
     m_callbacks.clear();
+    m_channel.reset();
 }
 
 int ApiInterfaceImpl::process(int fd, int events)
 {
-    return m_channel.process(fd, eventsToAskUserMask(events));
+    return m_channel->process(fd, eventsToAskUserMask(events));
 }
 
 askuser_check_result ApiInterfaceImpl::checkPrivilege(const std::string &privilege)
@@ -124,7 +127,7 @@ askuser_check_result ApiInterfaceImpl::checkPrivilege(const std::string &privile
 RequestId ApiInterfaceImpl::popupRequest(const PopupCallbackClosure &closure,
                                          const std::string &privilege)
 {
-    Client::RequestId id = static_cast<Client::RequestId>(m_channel.popupRequest(privilege));
+    Client::RequestId id = static_cast<Client::RequestId>(m_channel->popupRequest(privilege));
 
     auto it = m_callbacks.find(id);
     if (it != m_callbacks.end()) {
index 0b45410f99f025230f5bad774e275af954784c13..2726a7675a310ed660a7cce590eb6da20225c983 100644 (file)
@@ -55,7 +55,7 @@ public:
 
 private:
     StatusCallbackClosure m_statusClosure;
-    Protocol::ClientChannel m_channel;
+    std::unique_ptr<Protocol::ClientChannel> m_channel;
     std::map<RequestId, PopupCallbackClosure> m_callbacks;
 };
 
index bf6b6708935c9293c92572e4a53d199113918ced..43300c7f524f364bcd016f44ba0839d5a20bd338 100644 (file)
@@ -166,6 +166,11 @@ void Logic::popup(Protocol::ConnectionFd fd, Protocol::RequestId id, const std::
     addEvent({fd, id}, new EventPopupCheck(&m_popupper, pkgId, privilege));
 }
 
+Logic::~Logic()
+{
+    m_serverChannel.reset();
+}
+
 bool Logic::isEventProcessed() {
     return m_currentEvent.fd != Protocol::INVALID_FD;
 }
index d05c04368795d81aec91f03029f340d70c273d25..be066cb1aaf3db07bf8bc7322e5b658942d0defe 100644 (file)
@@ -52,7 +52,7 @@ public:
 
     void popup(Protocol::ConnectionFd fd, Protocol::RequestId id, const std::string &privilege);
 
-    ~Logic() {}
+    ~Logic();
 private:
     struct EventId {
         EventId() : fd(Protocol::INVALID_FD), id(Protocol::INVALID_ID) {}