Fix memory leak after calloc 28/268428/2
authorwn.jang <wn.jang@samsung.com>
Thu, 23 Dec 2021 01:57:30 +0000 (10:57 +0900)
committerwn.jang <wn.jang@samsung.com>
Thu, 23 Dec 2021 02:08:55 +0000 (11:08 +0900)
Change-Id: Id900d12edfc51aff8356b5a7d659846e7d805cc3

src/vc_elm_efl_dump.c

index 2e027cb..067b720 100644 (file)
@@ -253,14 +253,14 @@ _obj_tree_items(Ea_Util_Mgr *util_mgr, Evas_Object *obj, Object_Info *parent)
                object_info->type = calloc(1, strlen("swallow") + 1);
                if (!object_info->type) {
                        VC_ELM_LOG_ERR("[ERROR] Fail to allocate memory");
-                       return;
+                       goto exit;
                }
                strncpy(object_info->type, "swallow", strlen("swallow") + 1);
        } else if (evas_object_type_match(obj, "rectangle")) {
                object_info->type = calloc(1, strlen("rect") + 1);
                if (!object_info->type) {
                        VC_ELM_LOG_ERR("[ERROR] Fail to allocate memory");
-                       return;
+                       goto exit;
                }
                strncpy(object_info->type, "rect", strlen("rect") + 1);
                evas_object_color_get(obj, &r, &g, &b, &a);
@@ -272,7 +272,7 @@ _obj_tree_items(Ea_Util_Mgr *util_mgr, Evas_Object *obj, Object_Info *parent)
                object_info->type = calloc(1, strlen(EVAS_OBJECT_TYPE_GET(obj)) + 1);
                if (!object_info->type) {
                        VC_ELM_LOG_ERR("[ERROR] Fail to allocate memory");
-                       return;
+                       goto exit;
                }
                strncpy(object_info->type, EVAS_OBJECT_TYPE_GET(obj), strlen(EVAS_OBJECT_TYPE_GET(obj)) + 1);
        }
@@ -303,7 +303,7 @@ _obj_tree_items(Ea_Util_Mgr *util_mgr, Evas_Object *obj, Object_Info *parent)
                        object_info->group = calloc(1, strlen(group) + 1);
                        if (!object_info->group) {
                                VC_ELM_LOG_ERR("[ERROR] Fail to allocate memory");
-                               return;
+                               goto exit;
                        }
                        strncpy(object_info->group, group, strlen(group) + 1);
                }
@@ -321,7 +321,7 @@ _obj_tree_items(Ea_Util_Mgr *util_mgr, Evas_Object *obj, Object_Info *parent)
                                        object_info->color_class = calloc(1, strlen(edje_info->color_class) + 1);
                                        if (!object_info->color_class) {
                                                VC_ELM_LOG_ERR("[ERROR] Fail to allocate memory");
-                                               return;
+                                               goto exit;
                                        }
                                        strncpy(object_info->color_class, edje_info->color_class, strlen(edje_info->color_class) + 1);
                                }
@@ -331,7 +331,7 @@ _obj_tree_items(Ea_Util_Mgr *util_mgr, Evas_Object *obj, Object_Info *parent)
                                object_info->part_state = calloc(1, strlen(ret) + 1);
                                if (!object_info->part_name || !object_info->part_state) {
                                        VC_ELM_LOG_ERR("[ERROR] Fail to allocate memory");
-                                       return;
+                                       goto exit;
                                }
                                strncpy(object_info->part_name, edje_info->part_name, strlen(edje_info->part_name) + 1);
                                strncpy(object_info->part_state, ret, strlen(ret) + 1);
@@ -340,7 +340,7 @@ _obj_tree_items(Ea_Util_Mgr *util_mgr, Evas_Object *obj, Object_Info *parent)
                                        object_info->image_name = calloc(1, strlen(edje_info->image_name) + 1);
                                        if (!object_info->image_name) {
                                                VC_ELM_LOG_ERR("[ERROR] Fail to allocate memory");
-                                               return;
+                                               goto exit;
                                        }
                                        strncpy(object_info->image_name, edje_info->image_name, strlen(edje_info->image_name) + 1);
                                }
@@ -366,7 +366,7 @@ _obj_tree_items(Ea_Util_Mgr *util_mgr, Evas_Object *obj, Object_Info *parent)
                object_info->text = calloc(1, strlen(text) + 1);
                if (!object_info->text) {
                        VC_ELM_LOG_ERR("[ERROR] Fail to allocate memory");
-                       return;
+                       goto exit;
                }
                strncpy(object_info->text, text, strlen(text) + 1);
        }
@@ -378,6 +378,18 @@ next:
                EINA_LIST_FREE(children, child)
                        _obj_tree_items(util_mgr, child, object_info);
        }
+       return;
+
+exit:
+       free(object_info->type);
+       free(object_info->group);
+       free(object_info->color_class);
+       free(object_info->part_name);
+       free(object_info->part_state);
+       free(object_info->image_name);
+       free(object_info->text);
+       free(object_info);
+       return;
 }
 
 static Eina_Bool _is_clickable_object(Evas_Object *obj)
@@ -565,14 +577,14 @@ _obj_tree_items_exclude_unfocusable_text(Ea_Util_Mgr *util_mgr, Evas_Object *obj
                object_info->type = calloc(1, strlen("swallow") + 1);
                if (!object_info->type) {
                        VC_ELM_LOG_ERR("[ERROR] Fail to allocate memory");
-                       return;
+                       goto exit;
                }
                strncpy(object_info->type, "swallow", strlen("swallow") + 1);
        } else if (evas_object_type_match(obj, "rectangle")) {
                object_info->type = calloc(1, strlen("rect") + 1);
                if (!object_info->type) {
                        VC_ELM_LOG_ERR("[ERROR] Fail to allocate memory");
-                       return;
+                       goto exit;
                }
                strncpy(object_info->type, "rect", strlen("rect") + 1);
                evas_object_color_get(obj, &r, &g, &b, &a);
@@ -584,7 +596,7 @@ _obj_tree_items_exclude_unfocusable_text(Ea_Util_Mgr *util_mgr, Evas_Object *obj
                object_info->type = calloc(1, strlen(EVAS_OBJECT_TYPE_GET(obj)) + 1);
                if (!object_info->type) {
                        VC_ELM_LOG_ERR("[ERROR] Fail to allocate memory");
-                       return;
+                       goto exit;
                }
                strncpy(object_info->type, EVAS_OBJECT_TYPE_GET(obj), strlen(EVAS_OBJECT_TYPE_GET(obj)) + 1);
        }
@@ -615,7 +627,7 @@ _obj_tree_items_exclude_unfocusable_text(Ea_Util_Mgr *util_mgr, Evas_Object *obj
                        object_info->group = calloc(1, strlen(group) + 1);
                        if (!object_info->group) {
                                VC_ELM_LOG_ERR("[ERROR] Fail to allocate memory");
-                               return;
+                               goto exit;
                        }
                        strncpy(object_info->group, group, strlen(group) + 1);
                }
@@ -633,7 +645,7 @@ _obj_tree_items_exclude_unfocusable_text(Ea_Util_Mgr *util_mgr, Evas_Object *obj
                                        object_info->color_class = calloc(1, strlen(edje_info->color_class) + 1);
                                        if (!object_info->color_class) {
                                                VC_ELM_LOG_ERR("[ERROR] Fail to allocate memory");
-                                               return;
+                                               goto exit;
                                        }
                                        strncpy(object_info->color_class, edje_info->color_class, strlen(edje_info->color_class) + 1);
                                }
@@ -643,7 +655,7 @@ _obj_tree_items_exclude_unfocusable_text(Ea_Util_Mgr *util_mgr, Evas_Object *obj
                                object_info->part_state = calloc(1, strlen(ret) + 1);
                                if (!object_info->part_name || !object_info->part_state) {
                                        VC_ELM_LOG_ERR("[ERROR] Fail to allocate memory");
-                                       return;
+                                       goto exit;
                                }
                                strncpy(object_info->part_name, edje_info->part_name, strlen(edje_info->part_name) + 1);
                                strncpy(object_info->part_state, ret, strlen(ret) + 1);
@@ -652,7 +664,7 @@ _obj_tree_items_exclude_unfocusable_text(Ea_Util_Mgr *util_mgr, Evas_Object *obj
                                        object_info->image_name = calloc(1, strlen(edje_info->image_name) + 1);
                                        if (!object_info->image_name) {
                                                VC_ELM_LOG_ERR("[ERROR] Fail to allocate memory");
-                                               return;
+                                               goto exit;
                                        }
                                        strncpy(object_info->image_name, edje_info->image_name, strlen(edje_info->image_name) + 1);
                                }
@@ -724,7 +736,7 @@ _obj_tree_items_exclude_unfocusable_text(Ea_Util_Mgr *util_mgr, Evas_Object *obj
                object_info->text = calloc(1, strlen(text) + 1);
                if (!object_info->text) {
                        VC_ELM_LOG_ERR("[ERROR] Fail to allocate memory");
-                       return;
+                       goto exit;
                }
                strncpy(object_info->text, text, strlen(text) + 1);
        }
@@ -738,6 +750,16 @@ next:
                if (evas_object_type_match(obj, "elm_popup") || evas_object_type_match(obj, "elm_ctxpopup")) find_popup = 1;
        }
        VC_ELM_LOG_DUMP("   [%d] %s : return", cnt, EVAS_OBJECT_TYPE_GET(obj));
+
+exit:
+       free(object_info->type);
+       free(object_info->group);
+       free(object_info->color_class);
+       free(object_info->part_name);
+       free(object_info->part_state);
+       free(object_info->image_name);
+       free(object_info->text);
+       free(object_info);
 }
 
 static void