fix memory leak at on_manager_getmodems() 02/69702/1 accepted/tizen/3.0/common/20161114.110104 accepted/tizen/3.0/ivi/20161011.065155 accepted/tizen/3.0/mobile/20161015.034422 accepted/tizen/3.0/tv/20161016.005743 accepted/tizen/3.0/wearable/20161015.084451 accepted/tizen/common/20160516.143531 accepted/tizen/ivi/20160517.032655 accepted/tizen/mobile/20160517.032929 accepted/tizen/tv/20160517.032716 accepted/tizen/wearable/20160517.032755 submit/tizen/20160516.121150 submit/tizen_3.0_common/20161104.104000 submit/tizen_3.0_ivi/20161010.000007 submit/tizen_3.0_mobile/20161015.000007 submit/tizen_3.0_tv/20161015.000005 submit/tizen_3.0_wearable/20161015.000006
authorJooseok Park <jooseok.park@samsung.com>
Mon, 16 May 2016 10:48:55 +0000 (19:48 +0900)
committerJooseok Park <jooseok.park@samsung.com>
Mon, 16 May 2016 10:48:55 +0000 (19:48 +0900)
Change-Id: I6aa4f41d844b0270a9906ff1538eeddd7ba9d194

packaging/tel-plugin-dbus_tapi.spec
src/dtapi_main.c

index f641ad90250e2492307d5bde572b1c44855cd2d3..8fa6388c836e59e8a13d2c4a1cd3d7fefe24140c 100644 (file)
@@ -1,6 +1,6 @@
 %define major 0
 %define minor 3
-%define patchlevel 73
+%define patchlevel 74
 
 Name:           tel-plugin-dbus_tapi
 Version:        %{major}.%{minor}.%{patchlevel}
index b901fb49620bdfab123e8221c3738230959a11f9..face919f98f5273ab02f51ce66923cc676f12d12 100644 (file)
@@ -218,9 +218,10 @@ static gboolean on_manager_getmodems(TelephonyManager *mgr,
 {
        struct custom_data *ctx = user_data;
        GSList *cp_name_list;
+       GSList *cp_name_list_temp;
        gchar **list;
        const char *name = NULL;
-       int count;
+       int count, index;
 
        cp_name_list = tcore_server_get_cp_name_list(ctx->server);
        if (cp_name_list == NULL) {
@@ -240,22 +241,23 @@ static gboolean on_manager_getmodems(TelephonyManager *mgr,
                return TRUE;
        }
 
-       count = 0;
-       for ( ; cp_name_list ; cp_name_list = cp_name_list->next) {
-               name = cp_name_list->data;
-               list[count] = g_strdup(name);
-               dbg("list[%d]: %s", count, list[count]);
-               count++;
+       /*
+        * fix memory leak
+        *  - Shouldn't move directly GSList pointer which is allocated in g_slist_append().
+        *  - It cause memory leak.
+        */
+       for (index = 0; index < count; index++) {
+               cp_name_list_temp = g_slist_nth(cp_name_list, index);
+               if(cp_name_list_temp == NULL)
+                       continue;
+               list[index] = g_strdup(cp_name_list_temp->data);
+               dbg("list[%d]: %s", index, list[index]);
        }
 
        telephony_manager_complete_get_modems(mgr, invocation, (const gchar **)list);
 
        /* Free memory */
-       for (; count >= 0; count--)
-               g_free(list[count]);
-       g_free(list);
-
-       /* Freeing the received list of CP names */
+       g_strfreev(list);
        g_slist_free_full(cp_name_list, g_free);
 
        return TRUE;