From 3605f374edfe1ddb0b6749f87727e20202e09dc4 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Wed, 2 May 2018 18:25:00 +0900 Subject: [PATCH] Fix memory leak in app control Change-Id: I5c08fc89481759b3f1318e657ff6f47b47a82cb4 Signed-off-by: lokilee73 --- src/mmc/mmc-mobile.c | 16 ++++++++++------ src/usb/usbotg-mobile.c | 16 ++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/mmc/mmc-mobile.c b/src/mmc/mmc-mobile.c index 27e1686..dece299 100755 --- a/src/mmc/mmc-mobile.c +++ b/src/mmc/mmc-mobile.c @@ -128,7 +128,7 @@ static void send_mount_signal(char *signal) static void launch_app(int type) { app_control_h app_control = NULL; - int ret; + int ret = -1; ret = app_control_create(&app_control); if (ret != APP_CONTROL_ERROR_NONE) @@ -146,19 +146,23 @@ static void launch_app(int type) ret = app_control_set_app_id(app_control, ODE_APPNAME); } else { _E("No matched type(%d)", type); - return; + goto out; } if (ret != APP_CONTROL_ERROR_NONE) { - (void)app_control_destroy(app_control); - return; + _E("Fail to set app id"); + goto out; } ret = app_control_send_launch_request(app_control, NULL, NULL); if (ret != APP_CONTROL_ERROR_NONE) - _E("Failed to send launch request"); + _E("Fail to send launch request"); - (void)app_control_destroy(app_control); +out: + if (app_control) { + (void)app_control_destroy(app_control); + app_control = NULL; + } } static void send_general_mount_signal(const struct popup_ops *ops) diff --git a/src/usb/usbotg-mobile.c b/src/usb/usbotg-mobile.c index d83bba5..abc7607 100755 --- a/src/usb/usbotg-mobile.c +++ b/src/usb/usbotg-mobile.c @@ -107,7 +107,7 @@ static void launch_app(int type) { app_control_h app_control; - int ret, i, type_len; + int ret = -1, i, type_len; type_len = ARRAY_SIZE(app_type); for (i = 0 ; i < ARRAY_SIZE(app_type) ; i++) { @@ -129,19 +129,23 @@ static void launch_app(int type) ret = app_control_set_app_id(app_control, GALLERY_APPNAME); else { _E("No matched type(%d)", type); - return; + goto out; } if (ret != APP_CONTROL_ERROR_NONE) { - (void)app_control_destroy(app_control); - return; + _E("Fail to set app id"); + goto out; } ret = app_control_send_launch_request(app_control, NULL, NULL); if (ret != APP_CONTROL_ERROR_NONE) - _E("Failed to send launch request"); + _E("Fail to send launch request"); - (void)app_control_destroy(app_control); +out: + if (app_control) { + (void)app_control_destroy(app_control); + app_control = NULL; + } } static void storage_browse(const struct popup_ops *ops) -- 2.7.4