Use mutex instead of copying of network_info inside event handler 29/244729/2 accepted/tizen/unified/20201029.124903 submit/tizen/20201008.114009 submit/tizen/20201028.023046
authorNishant Chaprana <n.chaprana@samsung.com>
Wed, 23 Sep 2020 15:15:54 +0000 (20:45 +0530)
committerNishant Chaprana <n.chaprana@samsung.com>
Thu, 24 Sep 2020 01:54:53 +0000 (07:24 +0530)
Change-Id: Ia8f8b86ed6ea293c3ed6703109dce020d276871f
Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
packaging/capi-network-connection.spec
src/libnetwork.c

index 69e3da9..26d0699 100755 (executable)
@@ -1,6 +1,6 @@
 Name:          capi-network-connection
 Summary:       Network Connection library in TIZEN C API
-Version:       1.0.122
+Version:       1.0.123
 Release:       1
 Group:         System/Network
 License:       Apache-2.0
index 89d3cdb..401841c 100755 (executable)
@@ -170,20 +170,16 @@ static void __libnet_clear_profile_list(struct _profile_list_s *profile_list)
 
 static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data)
 {
+       CONN_LOCK;
        bool is_requested = false;
        connection_error_e result = CONNECTION_ERROR_NONE;
-       CONN_LOCK;
-       connection_handle_s conn_handle_local;
-       connection_handle_s *conn_handle = &conn_handle_local;
-       connection_handle_s *conn_handle_origin = (connection_handle_s *)user_data;
+       connection_handle_s *conn_handle = (connection_handle_s *)user_data;
 
-       if(!_connection_check_handle_validity(conn_handle_origin)) {
+       if (!_connection_check_handle_validity(conn_handle)) {
                CONNECTION_LOG(CONNECTION_INFO, "Invalid handle");
                CONN_UNLOCK;
                return;
        }
-       memcpy(conn_handle, conn_handle_origin, sizeof(connection_handle_s));
-       CONN_UNLOCK;
 
        switch (event_cb->Event) {
        case NET_EVENT_OPEN_RSP:
@@ -211,6 +207,7 @@ static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data)
                        CONNECTION_LOG(CONNECTION_INFO, "Successfully open connection");
 
                        __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_CONNECTED);
+                       CONN_UNLOCK;
                        return;
                default:
                        CONNECTION_LOG(CONNECTION_ERROR, "Failed to open connection[%s]",
@@ -244,6 +241,7 @@ static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data)
                        CONNECTION_LOG(CONNECTION_INFO, "Successfully closed connection");
 
                        __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED);
+                       CONN_UNLOCK;
                        return;
                default:
                        CONNECTION_LOG(CONNECTION_ERROR, "Failed to close connection[%s]",
@@ -254,8 +252,10 @@ static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data)
        case NET_EVENT_NET_STATE_IND:
                CONNECTION_LOG(CONNECTION_INFO, "State changed IND");
 
-               if (event_cb->Datalength != sizeof(net_state_type_t))
+               if (event_cb->Datalength != sizeof(net_state_type_t)) {
+                       CONN_UNLOCK;
                        return;
+               }
 
                net_state_type_t *profile_state = (net_state_type_t *)event_cb->Data;
                connection_profile_state_e cp_state = _profile_convert_to_cp_state(*profile_state);
@@ -422,6 +422,8 @@ static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data)
        default:
                break;
        }
+
+       CONN_UNLOCK;
 }
 //LCOV_EXCL_STOP