Fix GVariant memory allocation issues for tests 77/237477/2 submit/tizen/20200713.070440
authorYu <jiung.yu@samsung.com>
Tue, 30 Jun 2020 23:30:27 +0000 (08:30 +0900)
committerYu <jiung.yu@samsung.com>
Mon, 13 Jul 2020 04:19:29 +0000 (13:19 +0900)
Change-Id: Ic5bf4137c047ae9653065b98f7cec0e40dcdd649
Signed-off-by: Yu jiung <jiung.yu@samsung.com>
packaging/wifi-direct-manager.spec
unittest/event_injector.cpp
unittest/method_injector.cpp
unittest/unittest.cpp

index f354c3b..cb20cc6 100644 (file)
@@ -6,7 +6,7 @@
 
 Name:          wifi-direct-manager
 Summary:       Wi-Fi Direct manger
-Version:       1.2.281
+Version:       1.2.282
 Release:       1
 Group:      Network & Connectivity/Wireless
 License:    Apache-2.0
index ec1f7ed..3b85ea5 100644 (file)
@@ -45,12 +45,37 @@ EventInjector::EventInjector()
        this->event_data = g_try_malloc0(sizeof(wfd_oem_event_s));
 }
 
+static void __destroy_asp_service(gpointer data)
+{
+       wfd_oem_advertise_service_s *service;
+
+       service  = (wfd_oem_advertise_service_s *)data;
+       g_free(service->service_type);
+       g_free(service->instance_name);
+       g_free(service);
+
+       return;
+}
+
+static void __destroy_wfds(gpointer data)
+{
+       wfd_oem_new_service_s * service = (wfd_oem_new_service_s *)data;
+       if (service->protocol == WFD_OEM_SERVICE_TYPE_BONJOUR) {
+               g_free(service->data.bonjour.query);
+               g_free(service->data.bonjour.rdata);
+       } else if (service->protocol == WFD_OEM_SERVICE_TYPE_UPNP) {
+               g_free(service->data.upnp.version);
+               g_free(service->data.upnp.service);
+       }
+       g_free(service);
+}
+
 EventInjector::~EventInjector()
 {
        wfd_oem_event_s *data = (wfd_oem_event_s *)this->event_data;
        if (data) {
                if (data->edata_type == WFD_OEM_EDATA_TYPE_NEW_SERVICE) {
-                       g_list_free((GList*) data->edata);
+                       g_list_free_full((GList*) data->edata, __destroy_wfds);
                        data->edata = NULL;
                }
 
@@ -60,6 +85,7 @@ EventInjector::~EventInjector()
                        g_free(service->service_type);
                        g_free(service->service_info);
                        g_free(service);
+                       data->edata = NULL;
                }
 
                if (data->edata_type == WFD_OEM_EDATA_TYPE_ASP_PROV) {
@@ -70,32 +96,23 @@ EventInjector::~EventInjector()
 
                }
 
-               if (data->edata)
+               if (data->edata) {
                        g_free(data->edata);
+                       data->edata = NULL;
+               }
 
-               if (data->asp_services != NULL) {
-                       GList *l;
-                       wfd_oem_advertise_service_s *service;
-                       for (l = (GList *)data->asp_services; l != NULL; l = l->next) {
-                               service = (wfd_oem_advertise_service_s *)l->data;
-                               data->asp_services = g_list_remove(l, service);
-                               g_free(service->service_type);
-                               g_free(service);
-                       }
+               if (data->asp_services) {
+                       g_list_free_full((GList *)data->asp_services, __destroy_asp_service);
+                       data->asp_services = NULL;
                }
-               if (data->asp2_services != NULL) {
-                       GList *l;
-                       wfd_oem_advertise_service_s *service;
-                       for (l = (GList *)data->asp2_services; l != NULL; l = l->next) {
-                               service = (wfd_oem_advertise_service_s *)l->data;
-                               data->asp_services = g_list_remove(l, service);
-                               g_free(service->service_type);
-                               g_free(service->instance_name);
-                               g_free(service);
-                       }
+
+               if (data->asp2_services) {
+                       g_list_free_full((GList *)data->asp2_services, __destroy_asp_service);
+                       data->asp2_services = NULL;
                }
 
                g_free(data);
+               this->event_data  = NULL;
        }
 }
 
@@ -124,7 +141,7 @@ void EventInjector::InitData()
        wfd_oem_event_s *event = NULL;
        event = (wfd_oem_event_s *)this->event_data;
        if (event->edata_type == WFD_OEM_EDATA_TYPE_NEW_SERVICE) {
-               g_list_free((GList*) event->edata);
+               g_list_free_full((GList*) event->edata, __destroy_wfds);
                event->edata = NULL;
        }
 
@@ -148,27 +165,16 @@ void EventInjector::InitData()
                g_free(event->edata);
        }
 
-       if (event->asp_services != NULL) {
-               GList *l;
-               wfd_oem_advertise_service_s *service;
-               for (l = (GList *)event->asp_services; l != NULL; l = l->next) {
-                       service = (wfd_oem_advertise_service_s *)l->data;
-                       event->asp_services = g_list_remove(l, service);
-                       g_free(service->service_type);
-                       g_free(service);
-               }
+       if (event->asp_services) {
+               g_list_free_full((GList *)event->asp_services, __destroy_asp_service);
+               event->asp_services = NULL;
        }
-       if (event->asp2_services != NULL) {
-               GList *l;
-               wfd_oem_advertise_service_s *service;
-               for (l = (GList *)event->asp2_services; l != NULL; l = l->next) {
-                       service = (wfd_oem_advertise_service_s *)l->data;
-                       event->asp_services = g_list_remove(l, service);
-                       g_free(service->service_type);
-                       g_free(service->instance_name);
-                       g_free(service);
-               }
+
+       if (event->asp2_services) {
+               g_list_free_full((GList *)event->asp2_services, __destroy_asp_service);
+               event->asp2_services = NULL;
        }
+
        memset(event, 0, sizeof(wfd_oem_event_s));
 }
 
@@ -1048,12 +1054,12 @@ void *EventInjector::AspServiceFound()
 {
        wfd_oem_event_s *event = NULL;
        wfd_oem_asp_service_s *service = NULL;
-       char *asp_service_type = strdup("asp_service_type");
-       char *service_info = strdup("service_info");
+       char *asp_service_type = g_strdup("asp_service_type");
+       char *service_info = g_strdup("service_info");
        this->InitData();
 
        event = (wfd_oem_event_s *)this->event_data;
-       service = (wfd_oem_asp_service_s *) g_try_malloc0(sizeof(wfd_oem_asp_service_s));
+       service = (wfd_oem_asp_service_s *)g_try_malloc0(sizeof(wfd_oem_asp_service_s));
 
        event->edata = (void*) service;
        event->edata_type = WFD_OEM_EDATA_TYPE_ASP_SERVICE;
index 67292e2..6d6015f 100644 (file)
@@ -52,9 +52,9 @@ MethodInjector::MethodInjector(const MethodInjector & Other)
 
 MethodInjector::~MethodInjector()
 {
-       if (MethodInjector::result) {
-               g_variant_unref(result);
-               result = NULL;
+       if (this->result) {
+               g_variant_unref(this->result);
+               this->result = NULL;
        }
 }
 
@@ -90,7 +90,6 @@ GVariant *MethodInjector::StartDiscoveryListen()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -117,7 +116,6 @@ GVariant *MethodInjector::StartDiscoveryFind()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -136,7 +134,6 @@ GVariant *MethodInjector::CreateGroup()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -150,7 +147,6 @@ GVariant *MethodInjector::Connect()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -164,7 +160,6 @@ GVariant *MethodInjector::AcceptConnect()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -178,7 +173,6 @@ GVariant *MethodInjector::RejectConnect()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -193,7 +187,6 @@ GVariant *MethodInjector::CancelConnect()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -207,7 +200,6 @@ GVariant *MethodInjector::SetDeviceName()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -221,7 +213,6 @@ GVariant *MethodInjector::SetReqWpsMode(int req_wps_mode)
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -235,7 +226,6 @@ GVariant *MethodInjector::SetGoIntent(int go_intent)
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -249,7 +239,6 @@ GVariant *MethodInjector::SetMaxClient(int max_client)
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -263,7 +252,6 @@ GVariant *MethodInjector::SetAutoConnection(bool mode)
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -277,7 +265,6 @@ GVariant *MethodInjector::SetSessionTimer(int session_timer)
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -291,7 +278,6 @@ GVariant *MethodInjector::GetPeerAddr()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -305,7 +291,6 @@ GVariant *MethodInjector::GetLegacyPeerAddr()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -319,7 +304,6 @@ GVariant *MethodInjector::SetWpsPin()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -333,7 +317,6 @@ GVariant *MethodInjector::SetPassphrase()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -347,7 +330,6 @@ GVariant *MethodInjector::SetDisplay()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 
@@ -362,7 +344,6 @@ GVariant *MethodInjector::SetDisplayAvail()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -376,7 +357,6 @@ GVariant *MethodInjector::SetAutoGroupRemoval(bool enable)
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -390,7 +370,6 @@ GVariant *MethodInjector::SetPersistentGroup(bool enable)
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -404,7 +383,6 @@ GVariant *MethodInjector::AddVsie()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -418,7 +396,6 @@ GVariant *MethodInjector::GetVsie()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -432,7 +409,6 @@ GVariant *MethodInjector::RemoveVsie()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -448,7 +424,6 @@ GVariant *MethodInjector::SrvStartDiscovery()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -464,7 +439,6 @@ GVariant *MethodInjector::SrvStopDiscovery()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -480,7 +454,6 @@ GVariant *MethodInjector::SrvRegister()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -496,7 +469,6 @@ GVariant *MethodInjector::SrvRegisterBonjourPtr()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -512,7 +484,6 @@ GVariant *MethodInjector::SrvRegisterBonjourTxt()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -526,7 +497,6 @@ GVariant *MethodInjector::SrvRegister(int type, char *srv_str)
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -541,7 +511,6 @@ GVariant *MethodInjector::SrvDeregister()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -569,7 +538,6 @@ GVariant *MethodInjector::AspAdvertise()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -583,7 +551,6 @@ GVariant *MethodInjector::AspAdvertiseCancel()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 
@@ -605,7 +572,6 @@ GVariant *MethodInjector::AspSeek()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -618,7 +584,6 @@ GVariant *MethodInjector::AspSeekCancel()
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
@@ -645,7 +610,6 @@ GVariant *MethodInjector::AspSessionConnect(const char *session_mac_str, unsigne
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 
@@ -675,7 +639,6 @@ GVariant *MethodInjector::AspSessionConfirm(const char *session_mac_str, int con
        if (this->result)
                g_variant_unref(this->result);
        this->result = res;
-       g_variant_ref(res);
 
        return res;
 }
index 172f98d..e679b42 100644 (file)
@@ -406,13 +406,15 @@ TEST(wfd_mgr_set_get, set_passphrase_handler_Negative2)
 TEST(wfd_mgr_set_get, set_passphrase_handler_Negative3)
 {
        wfd_manager_s * manager = NULL;
+       GVariant *parameters = g_variant_new("(s)", "0");
 
        INIT_WFD_MGR(manager);
        manager = wfd_get_manager();
 
-       set_passphrase_handler(g_variant_new("(s)", "0"), NULL);
+       set_passphrase_handler(parameters, NULL);
 
        wfd_manager_unload();
+       g_variant_unref(parameters);
 }
 
 TEST(wfd_mgr_set_get, set_get_go_intent_handler_Positive)
@@ -619,6 +621,8 @@ TEST(wfd_mgr_set_get, set_session_timer_handler_Negative)
 {
        MethodInjector *set_session_timer_method = new MethodInjector;
        set_session_timer_handler(set_session_timer_method->SetSessionTimer(10), NULL);
+
+       delete set_session_timer_method;
 }
 
 TEST(wfd_mgr_set_get, get_session_timer_handler_Negative)
@@ -660,6 +664,8 @@ TEST(wfd_mgr_set_get, set_persistent_group_handler_Negative)
 {
        MethodInjector *enable_persistent_group_method = new MethodInjector;
        set_persistent_group_handler(enable_persistent_group_method->SetPersistentGroup(true), NULL);
+
+       delete enable_persistent_group_method;
 }
 
 TEST(wfd_mgr_set_get, get_auto_group_removal_handler_Positive1)
@@ -2622,6 +2628,7 @@ TEST(wfd_mgr_connection, reject_connection_handler_Negative3)
        wfd_manager_unload();
 
        delete reject_connect_method;
+       delete connect_method;
 }
 
 TEST(wfd_mgr_connection, disconnect_handler_Positive1)
@@ -2872,6 +2879,7 @@ TEST(wfd_mgr_connection, legacy_connection_Positive)
        wfd_manager_unload();
 
        delete group_create_method;
+       delete event;
 }
 
 
@@ -2923,6 +2931,9 @@ TEST(wfd_mgr_connection, multi_connect_Positive)
        wfd_manager_unload();
 
        delete group_create_method;
+       delete accept_connect_method;
+       delete peer_addr;
+       delete event;
 }
 
 
@@ -3530,6 +3541,7 @@ TEST(wfd_mgr_connect_keypad, keypad_connection_Positive1)
        delete connect_method;
        delete accept_connect_method;
        delete set_wps_pin_method;
+       delete set_req_wps_method;
 }
 
 TEST(wfd_mgr_connect_keypad, keypad_connection_Positive2)
@@ -3567,8 +3579,9 @@ TEST(wfd_mgr_connect_keypad, keypad_connection_Positive2)
 
        wfd_manager_unload();
 
-       delete accept_connect_method;
        delete event;
+       delete set_wps_pin_method;
+       delete accept_connect_method;
 }
 
 TEST(wfd_mgr_connect_keypad, keypad_connection_Positive3)
@@ -3619,6 +3632,8 @@ TEST(wfd_mgr_connect_keypad, keypad_connection_Positive3)
        delete event;
        delete connect_method;
        delete set_req_wps_method;
+       delete set_wps_pin_method;
+       delete accept_connect_method;
 }
 
 TEST(wfd_mgr_connect_keypad, keypad_connection_Positive4)
@@ -3807,6 +3822,7 @@ TEST(wfd_mgr_connect_display, display_connection_Positive1)
 
        delete event;
        delete connect_method;
+       delete set_req_wps_method;
 }
 
 TEST(wfd_mgr_connect_display, display_connection_Positive2)
@@ -3890,6 +3906,7 @@ TEST(wfd_mgr_connect_display, display_connection_Positive3)
 
        delete event;
        delete connect_method;
+       delete set_req_wps_method;
 }
 
 TEST(wfd_mgr_connect_display, display_connection_Positive4)
@@ -3931,6 +3948,7 @@ TEST(wfd_mgr_connect_display, display_connection_Positive4)
 
        wfd_manager_unload();
 
+       delete set_req_wps_method;
        delete accept_connect_method;
        delete event;
 }
@@ -4690,6 +4708,7 @@ TEST(wfd_mgr_asp, asp_peer_found_Positive)
 
        wfd_manager_unload();
 
+       delete event;
        delete asp_seek;
        delete asp_seek_cancel;
 }
@@ -4724,6 +4743,7 @@ TEST(wfd_mgr_asp, asp_service_found_Positive)
 
        delete asp_seek;
        delete asp_seek_cancel;
+       delete event;
 }
 
 TEST(wfd_mgr_asp, asp_connect_session_Positive1)