Check the return value of connect() function. 89/184189/1
authorkibak.yoon <kibak.yoon@samsung.com>
Mon, 16 Jul 2018 06:57:28 +0000 (15:57 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Mon, 16 Jul 2018 06:57:28 +0000 (15:57 +0900)
If there is a connection fail, the API should return the proper error.

Change-Id: I39fca464ee86442d060702ca5782650be7ce5614
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
src/client/sensor_manager.cpp
src/shared/ipc_client.cpp

index 41e689e..7576fc9 100644 (file)
@@ -198,6 +198,7 @@ void sensor_manager::deinit(void)
 
 bool sensor_manager::connect_channel(void)
 {
+       bool ret;
        ipc::message msg;
 
        m_cmd_channel = m_client->connect(NULL);
@@ -207,7 +208,8 @@ bool sensor_manager::connect_channel(void)
        retvm_if(!m_mon_channel, false, "Failed to connect to server");
 
        msg.set_type(CMD_MANAGER_CONNECT);
-       m_mon_channel->send_sync(&msg);
+       ret = m_mon_channel->send_sync(&msg);
+       retvm_if(!ret, false, "Failed to send message");
 
        m_connected.store(true);
 
index 1376ac7..1f013b0 100644 (file)
@@ -52,6 +52,7 @@ channel *ipc_client::connect(channel_handler *handler)
 
 channel *ipc_client::connect(channel_handler *handler, event_loop *loop, bool bind)
 {
+       bool ret;
        socket *sock;
        channel *ch;
        channel_event_handler *ev_handler;
@@ -75,11 +76,18 @@ channel *ipc_client::connect(channel_handler *handler, event_loop *loop, bool bi
        if (!ev_handler) {
                delete ch;
                delete sock;
-               _E("Faield to allocate memory");
+               _E("Failed to allocate memory");
                return NULL;
        }
 
-       ch->connect(ev_handler, loop);
+       ret = ch->connect(ev_handler, loop);
+       if (!ret) {
+               delete ev_handler;
+               delete ch;
+               delete sock;
+               _E("Failed to connect server");
+               return NULL;
+       }
 
        if (loop && bind) {
                uint64_t id = loop->add_event(sock->get_fd(),