Fix memory leak 27/259527/3
authorHyunho <hhstark.kang@samsung.com>
Wed, 9 Jun 2021 08:56:04 +0000 (17:56 +0900)
committerHyunho <hhstark.kang@samsung.com>
Thu, 10 Jun 2021 02:07:36 +0000 (11:07 +0900)
Change-Id: I12225628efded0412440f4ad0a55d8be50e06cb1
Signed-off-by: Hyunho <hhstark.kang@samsung.com>
widget_viewer_sdk/src/main.c

index a353a4f..effeb4e 100644 (file)
@@ -829,13 +829,13 @@ static void __watch_ambient_event_cb(
        DbgPrint("watch ambient event (%d) from (%s)", event, sender);
 }
 
-static void _app_control(app_control_h service, void *data)
+static void _app_control(app_control_h service, void *user_data)
 {
        char *widget_id = NULL;
        int ret;
        char *app_type = NULL;
-       pkgmgrinfo_appinfo_h app_info;
-       bundle *b;
+       pkgmgrinfo_appinfo_h app_info = NULL;
+       bundle *data = NULL;
        bundle *app_control_b;
        char *lazy_loader = NULL;
        bool is_array;
@@ -869,10 +869,6 @@ static void _app_control(app_control_h service, void *data)
                                                DEFAULT_WATCH);
                        }
                }
-
-               if (cur_watch)
-                       free(cur_watch);
-
                evas_object_resize(s_info.win, s_info.w, s_info.h);
 
                watch_holder_lifecycle_st lifecycle;
@@ -885,36 +881,34 @@ static void _app_control(app_control_h service, void *data)
                lifecycle.watch_holder_lifecycle_ambient_changed_cb = __watch_ambient_changed_cb;
                lifecycle.watch_holder_lifecycle_ambient_event_cb = __watch_ambient_event_cb;
 
-               if (__watch_holder != NULL)
+               if (__watch_holder != NULL) {
                        watch_holder_destroy(__watch_holder);
+                       __watch_holder = NULL;
+               }
 
                ret = watch_holder_create(s_info.win, lifecycle, &s_info, &__watch_holder);
                if (ret != WATCH_HOLDER_ERROR_NONE) {
                        ErrPrint("Watch Holder Error:%d", ret);
-                       free(widget_id);
-                       return;
+                       goto end;
                }
 
-               b = bundle_create();
-               if (b == NULL) {
+               data = bundle_create();
+               if (data == NULL) {
                        ErrPrint("Out of memory");
-                       free(widget_id);
-                       return;
+                       goto end;
                }
 
                app_control_to_bundle(service, &app_control_b);
-               __set_bundle_for_watchapp(app_control_b, b);
-               ret = watch_holder_launch(__watch_holder, false, widget_id, b);
+               __set_bundle_for_watchapp(app_control_b, data);
+               ret = watch_holder_launch(__watch_holder, false, widget_id, data);
                if (ret < 0)
                        ErrPrint("Watch Holder Launch Error:%d", ret);
                else
                        DbgPrint("Watch Holder Launch pid(%d)", ret);
-
-               bundle_free(b);
        } else {
                ret = app_control_get_extra_data(service, LAZY_LOADER, &lazy_loader);
-               app_control_to_bundle(service, &b);
-               widget_service_set_sdk_util(b);
+               app_control_to_bundle(service, &data);
+               widget_service_set_sdk_util(data);
                ret = unload_widget();
                ret = app_control_is_extra_data_array(service, WIDGET_APPID, &is_array);
                if (is_array) {
@@ -924,17 +918,30 @@ static void _app_control(app_control_h service, void *data)
                                free(widget_id_arr[i]);
                        }
                        free(widget_id_arr);
-
                } else if (widget_id != NULL) {
                        _run_widget(widget_id, service, lazy_loader);
                } else {
                        __resume_process();
                        elm_win_activate(s_info.win);
                }
-               if (lazy_loader)
-                       free(lazy_loader);
        }
 
+end:
+       if (data)
+               bundle_free(data);
+
+       if (cur_watch)
+               free(cur_watch);
+
+       if (lazy_loader)
+               free(lazy_loader);
+
+       if (widget_id)
+               free(widget_id);
+
+       if (app_info)
+               pkgmgrinfo_appinfo_destroy_appinfo(app_info);
+
        if (widget_id)
                free(widget_id);
 }