mot-agent: fixed crash issue that memory corruption
authorsaerome.kim <saerome.kim@samsung.com>
Wed, 17 Jan 2018 06:03:43 +0000 (15:03 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:43 +0000 (19:38 +0900)
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
src/mot-agent/ma-subowner.c

index f03d73f46fcf79f6962fb31fe546576f3368dd7b..57b058ad7fbe9bc2f02a709defcfa33d83769691 100644 (file)
@@ -440,29 +440,20 @@ static void _remove_mot_client()
 
        ma_check_null_ret("g_client", g_client);
 
-       g_mutex_init(&motdev_mutex);
-       g_mutex_lock(&motdev_mutex);
        if (g_client->g_motdev_list) {
                OCDeleteDiscoveredDevices(g_client->g_motdev_list);
                g_client->g_motdev_list = NULL;
        }
-       g_mutex_unlock(&motdev_mutex);
 }
 
 static void _remove_owned_client()
 {
-       GMutex owned_dev_mutex;
-
        ma_check_null_ret("g_client", g_client);
 
-       /* delete un/owned device lists before updating them */
-       g_mutex_init(&owned_dev_mutex);
-       g_mutex_lock(&owned_dev_mutex);
        if (g_client->g_mowned_list) {
                OCDeleteDiscoveredDevices(g_client->g_mowned_list);
                g_client->g_mowned_list = NULL;
        }
-       g_mutex_unlock(&owned_dev_mutex);
 }
 
 static int _set_device_id_seed(void)
@@ -807,9 +798,6 @@ static gpointer _disc_mot_env_devs_func(gpointer data)
        ma_req_cb_s *con = (ma_req_cb_s *)data;
        ma_check_null_ret_error("con", con, NULL);
 
-       /* delete un/owned device lists before updating them */
-       _remove_mot_client();
-
        MA_LOGI("Discovering Multiple Ownership Transfer enabled Devices on Network..");
        if (OC_STACK_OK != OCDiscoverMultipleOwnerEnabledDevices(DISCOVERY_TIMEOUT,
                &g_client->g_motdev_list)) {
@@ -845,6 +833,9 @@ static int _disc_mot_enb_devs(ma_service *service)
        }
        g_thread_unref(con->thread);
 
+       /* delete un/owned device lists before updating them */
+       _remove_mot_client();
+
        con->userdata = service;
        con->cid = MA_DISC_MOT_ENB_DEVS;
 #ifdef TIMEOUT_USED
@@ -944,7 +935,6 @@ static gpointer _mot_func(gpointer data)
        ma_req_cb_s *con = (ma_req_cb_s *)data;
 
        OCProvisionDev_t *src_dev = NULL;
-       OCProvisionDev_t *clone_dev = NULL;
        OicUuid_t *uuid_target = NULL;
 
        if (!con->uuid_target_str) {
@@ -958,19 +948,16 @@ static gpointer _mot_func(gpointer data)
                MA_LOGE("We can't find in MOT dev list");
                goto MOT_ENDED;
        }
-       /* Copy subject device and related information */
-       clone_dev = PMCloneOCProvisionDev(src_dev);
-       /* To do ACL provisioning only one */
-       clone_dev->next = NULL;
 
        g_client->g_doneCB = false;
 
+#ifdef MULTIPLE_OWN_AT_ONCE
        OCProvisionDev_t* dev = NULL;
-       LL_FOREACH(clone_dev, dev) {
+       LL_FOREACH(src_dev, dev) {
                if(OIC_PRECONFIG_PIN == dev->doxm->oxmSel) {
                        /* Pre-Configured PIN initialization */
                        const char* testPreconfigPin = con->pin;/* Ex) "12341234" */
-                       ret = OCAddPreconfigPin(dev, testPreconfigPin, strlen(testPreconfigPin));
+                       ret = OCAddPreconfigPin(src_dev, testPreconfigPin, strlen(testPreconfigPin));
                        if(OC_STACK_OK != ret) {
                                MA_LOGE("Failed to save the pre-configured PIN");
                                MA_LOGE("You can't use the pre-configured PIN OxM for MOT");
@@ -978,8 +965,20 @@ static gpointer _mot_func(gpointer data)
                        }
                }
        }
+#else
+       if(OIC_PRECONFIG_PIN == src_dev->doxm->oxmSel) {
+               /* Pre-Configured PIN initialization */
+               const char* testPreconfigPin = con->pin;/* Ex) "12341234" */
+               ret = OCAddPreconfigPin(src_dev, testPreconfigPin, strlen(testPreconfigPin));
+               if(OC_STACK_OK != ret) {
+                       MA_LOGE("Failed to save the pre-configured PIN");
+                       MA_LOGE("You can't use the pre-configured PIN OxM for MOT");
+                       goto MOT_ENDED;
+               }
+       }
+#endif
 
-       ret = OCDoMultipleOwnershipTransfer(g_client, clone_dev, _mot_cb);
+       ret = OCDoMultipleOwnershipTransfer(g_client, src_dev, _mot_cb);
        if (OC_STACK_OK != ret )  {
                MA_LOGE( "OCDoMultipleOwnershipTransfer: ret = %d (%s)", ret, _error_to_string(ret));
                goto MOT_ENDED;
@@ -995,14 +994,14 @@ static gpointer _mot_func(gpointer data)
 
 MOT_ENDED:
 
-       net_ma_emit_mot_done(ma_dbus_get_object(), (int)ret);
        if (uuid_target)
                g_free(uuid_target);
-       if (clone_dev)
-               PMDeleteDeviceList(clone_dev);
+
        _request_cleanup(data);
        g_thread_exit(GINT_TO_POINTER (1));
 
+       net_ma_emit_mot_done(ma_dbus_get_object(), (int)ret);
+
        return NULL;
 }