Remove unused code & change calloc to g_malloc0
authorsaerome.kim <saerome.kim@samsung.com>
Thu, 21 Dec 2017 10:35:13 +0000 (19:35 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:38 +0000 (19:38 +0900)
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
src/d2d-subowner/d2ds-service.c
src/d2d-subowner/d2ds-subowner.c

index 8ee1775b423eb41e62a47742a29b550cd28a999b..650eef884e0d057a07a766ce781ab15f92c77c6a 100644 (file)
@@ -26,7 +26,7 @@ d2ds_service *d2ds_service_new()
 {\r
        d2ds_service *service;\r
 \r
-       service = calloc(1, sizeof(struct _d2ds_service));\r
+       service = g_malloc0(sizeof(struct _d2ds_service));\r
 \r
        /* Create g-main loop */\r
        service->main_loop = g_main_loop_new(NULL, FALSE);\r
index 0ef87e00a39187e6b6c5a6d3279c9e03de8101a6..e83d3150e947a031ba6854278c3c073da445c5f4 100644 (file)
@@ -62,7 +62,9 @@
 static const char* SVR_DB_FILE_NAME = "oic_svr_db_subowner_client.dat";
 static const char* PRVN_DB_FILE_NAME = "oic_pdm_subowner.db";
 
+#ifdef TEST
 static const OicSecPrm_t  SUPPORTED_PRMS[2] = { PRM_PRE_CONFIGURED, PRM_RANDOM_PIN };
+#endif
 
 typedef struct {
        d2ds_cmd_id_e cid; /**< Command ID */
@@ -118,6 +120,8 @@ static void _print_uuid(const OicUuid_t* uuid)
                (*uuid).id[12], (*uuid).id[13], (*uuid).id[14], (*uuid).id[15]);
        D2DS_LOGI("%s", uuid_string);
 }
+
+#ifdef TEST
 static OCProvisionDev_t* _get_dev_by_id(const OCProvisionDev_t* dev_lst, const int dev_num)
 {
        if(!dev_lst || 0>=dev_num) {
@@ -135,6 +139,7 @@ static OCProvisionDev_t* _get_dev_by_id(const OCProvisionDev_t* dev_lst, const i
 
     return NULL;
 }
+#endif
 
 static OCProvisionDev_t* _get_dev_by_uuid(const OCProvisionDev_t* dev_lst,
        const OicUuid_t* uuid)
@@ -304,7 +309,7 @@ static int _init_provision_client(void)
 
        SetInputPinCB(_input_pin_cb);
 
-       g_client = calloc(1, sizeof(d2ds_subowner_s));
+       g_client = g_malloc0(sizeof(d2ds_subowner_s));
        if(!g_client) {
                D2DS_LOGE( "memory allocation error = %d", errno);
                return D2DS_ERROR_OUT_OF_MEMORY;
@@ -331,23 +336,11 @@ static void _request_cleanup(gpointer data)
        }
        con->sid = 0;
        con->found = FALSE;
-#if 0
-       if (con->target) {
-               PMDeleteDeviceList(con->target);
-               con->target  = NULL;
-       }
-#endif
+
        if (con->pin) {
                free(con->pin);
                con->pin  = NULL;
        }
-#if 0
-       D2DS_LOGE("KSR : %p", con->subject);
-       if (con->subject) {
-               PMDeleteDeviceList(con->subject);
-               con->subject  = NULL;
-       }
-#endif
        if (con->rsrc_uri) {
                free(con->rsrc_uri);
                con->rsrc_uri = NULL;
@@ -370,6 +363,7 @@ static void _request_cleanup(gpointer data)
        }
 }
 
+#ifdef TEST
 static gboolean _d2ds_timeout_cb(gpointer data)
 {
        d2ds_req_cb_s *con = (d2ds_req_cb_s *)data;
@@ -409,6 +403,7 @@ static gboolean _d2ds_timeout_cb(gpointer data)
 
        return G_SOURCE_REMOVE;
 }
+#endif
 
 static gpointer _disc_mot_env_devs_func(gpointer data)
 {
@@ -438,9 +433,9 @@ DISC_MOT_ENB_DEVS_END:
 static int _disc_mot_enb_devs(d2ds_service *service)
 {
        d2ds_req_cb_s *con = NULL;
-       con = calloc(1, sizeof(d2ds_req_cb_s));
+       con = g_malloc0(sizeof(d2ds_req_cb_s));
        if (NULL == con) {
-               D2DS_LOGE( "calloc() Fail=%d", errno);
+               D2DS_LOGE( "g_malloc0() Fail=%d", errno);
                return D2DS_ERROR_OUT_OF_MEMORY;
        }
 
@@ -479,7 +474,7 @@ static gpointer _disc_owned_devs_func(gpointer data)
        g_client->g_mowndev_cnt = _print_dev_list(g_client->g_mowned_list);
 
 DISC_OWNED_DEVS_END:
-       _request_cleanup(data);
+       _request_cleanup(con);
        g_thread_exit(GINT_TO_POINTER (1));
 
        return NULL;
@@ -488,9 +483,9 @@ DISC_OWNED_DEVS_END:
 static int _disc_owned_devs(d2ds_service *service)
 {
        d2ds_req_cb_s *con = NULL;
-       con = calloc(1, sizeof(d2ds_req_cb_s));
+       con = g_malloc0(sizeof(d2ds_req_cb_s));
        if (NULL == con) {
-               D2DS_LOGE( "calloc() Fail=%d", errno);
+               D2DS_LOGE( "g_malloc0() Fail=%d", errno);
                return D2DS_ERROR_OUT_OF_MEMORY;
        }
 
@@ -574,9 +569,9 @@ OicUuid_t* _convert_uuid(const gchar *device_id)
        if (NULL == device_id)
                return NULL;
 
-       uuid = calloc(1, sizeof(struct OicUuid));
+       uuid = g_malloc0(sizeof(struct OicUuid));
        if (NULL == uuid) {
-               D2DS_LOGE("calloc() Fail(%d)", errno);
+               D2DS_LOGE("g_malloc0() Fail(%d)", errno);
                return NULL;
        }
 
@@ -615,9 +610,9 @@ static int _d2ds_mot(d2ds_service *service, gchar *uuid_str, gchar *pin)
        OCProvisionDev_t *src_dev = NULL;
 
        d2ds_req_cb_s *con = NULL;
-       con = calloc(1, sizeof(d2ds_req_cb_s));
+       con = g_malloc0(sizeof(d2ds_req_cb_s));
        if (NULL == con) {
-               D2DS_LOGE( "calloc() Fail=%d", errno);
+               D2DS_LOGE( "g_malloc0() Fail=%d", errno);
                /* Unset d2ds status 'pending' */
                g_atomic_int_set(&service->pending, 0);
                return D2DS_ERROR_OUT_OF_MEMORY;
@@ -639,7 +634,7 @@ static int _d2ds_mot(d2ds_service *service, gchar *uuid_str, gchar *pin)
        con->target->next = NULL;
 
        if (pin) {
-               con->pin = calloc(1, OXM_RANDOM_PIN_MAX_SIZE+1);
+               con->pin = g_malloc0(OXM_RANDOM_PIN_MAX_SIZE+1);
                if (!pin) {
                        D2DS_LOGE("Failed to allocate PIN number");
                        _request_cleanup(con);
@@ -953,9 +948,9 @@ static int _provisioning_acl(d2ds_service *service, gchar *target, gchar *subjec
        OCProvisionDev_t *subject_dev = NULL;
 
        d2ds_req_cb_s *con = NULL;
-       con = calloc(1, sizeof(d2ds_req_cb_s));
+       con = g_malloc0(sizeof(d2ds_req_cb_s));
        if (NULL == con) {
-               D2DS_LOGE( "calloc() Fail=%d", errno);
+               D2DS_LOGE( "g_malloc0() Fail=%d", errno);
                /* Unset d2ds status 'pending' */
                g_atomic_int_set(&service->pending, 0);
                return D2DS_ERROR_OUT_OF_MEMORY;
@@ -1058,7 +1053,7 @@ PVPWS_ERROR:
        return NULL;
 }
 
-static int _d2ds_provisioning_cred(d2ds_service *service,
+static int _provisioning_cred(d2ds_service *service,
        gchar *uuid_dev1, gchar *uuid_dev2)
 {
 
@@ -1067,9 +1062,9 @@ static int _d2ds_provisioning_cred(d2ds_service *service,
        OCProvisionDev_t *dev2 = NULL;
 
        d2ds_req_cb_s *con = NULL;
-       con = calloc(1, sizeof(d2ds_req_cb_s));
+       con = g_malloc0(sizeof(d2ds_req_cb_s));
        if (!con) {
-               D2DS_LOGE( "calloc() Fail=%d", errno);
+               D2DS_LOGE( "g_malloc0() Fail=%d", errno);
                /* Unset d2ds status 'pending' */
                g_atomic_int_set(&service->pending, 0);
                return D2DS_ERROR_OUT_OF_MEMORY;
@@ -1251,7 +1246,7 @@ int d2ds_request_prov_cred(d2ds_service *service, gchar *uuid_dev1, gchar *uuid_
        /* Set d2ds status 'pending' */
        g_atomic_int_set(&service->pending, 1);
 
-       ret = _d2ds_provisioning_cred(service, uuid_dev1, uuid_dev2);
+       ret = _provisioning_cred(service, uuid_dev1, uuid_dev2);
 
        return ret;
 }