From: Hwankyu Jhun Date: Mon, 11 Jan 2021 03:29:49 +0000 (+0900) Subject: Fix file descriptor management X-Git-Tag: submit/tizen_6.0/20210112.042453~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=03fbe2c72b1a9d29a1721c97f1ca0b8e28dc6fbe;p=platform%2Fcore%2Fappfw%2Famd.git Fix file descriptor management This patch removes double free and leakages. Change-Id: Ic8bed9d6ea9efd409005a56eada078978b498461 Signed-off-by: Hwankyu Jhun --- diff --git a/src/lib/amd_app_status.c b/src/lib/amd_app_status.c index bd943d12..6ec8df98 100644 --- a/src/lib/amd_app_status.c +++ b/src/lib/amd_app_status.c @@ -1125,8 +1125,8 @@ static int __send_running_appinfo(app_status_h app_status, int fd) if (b == NULL) { _E("out of memory"); aul_sock_send_raw_with_fd(fd, APP_GET_INFO_ERROR, - NULL, 0, AUL_SOCK_NOREPLY); - return -1; + NULL, 0, AUL_SOCK_ASYNC); + return -ENOMEM; } ret = bundle_encode(b, &raw, &len); @@ -1134,8 +1134,8 @@ static int __send_running_appinfo(app_status_h app_status, int fd) if (ret != BUNDLE_ERROR_NONE) { _E("Failed to encode bundle"); aul_sock_send_raw_with_fd(fd, APP_GET_INFO_ERROR, NULL, - 0, AUL_SOCK_NOREPLY); - return -1; + 0, AUL_SOCK_ASYNC); + return -ENOMEM; } ret = aul_sock_send_raw_with_fd(fd, APP_GET_INFO_OK, @@ -1191,8 +1191,9 @@ int _app_status_send_running_appinfo(int fd, int cmd, uid_t uid) ret = __send_running_appinfo(app_status, fd); if (ret < 0) { + close(fd); g_slist_free(list); - return -1; + return ret; } } close(fd); @@ -2255,10 +2256,10 @@ static int __dispatch_app_context_get(request_h req) } ret = __send_running_appinfo(app_status, fd); + close(fd); if (ret < 0) return ret; - close(fd); _I("[APP_CONTEXT_GET] result: %d", ret); return 0; } @@ -2322,10 +2323,10 @@ static int __dispatch_app_context_get_by_instance_id(request_h req) } ret = __send_running_appinfo(app_status, fd); + close(fd); if (ret < 0) return ret; - close(fd); _I("[APP_CONTEXT_GET_BY_INSTANCE_ID] result: %d", ret); return 0; } @@ -2378,10 +2379,10 @@ static int __dispatch_app_context_get_by_pid(request_h req) } ret = __send_running_appinfo(app_status, fd); + close(fd); if (ret < 0) return ret; - close(fd); _I("[APP_CONTEXT_GET_BY_PID] result: %d", ret); return 0; } @@ -2603,4 +2604,4 @@ int _app_status_finish(void) bool _app_status_is_debug_mode(app_status_h app_status) { return app_status->debug_mode; -} \ No newline at end of file +} diff --git a/src/lib/amd_launch.c b/src/lib/amd_launch.c index 9f315619..0dbc405e 100644 --- a/src/lib/amd_launch.c +++ b/src/lib/amd_launch.c @@ -154,6 +154,8 @@ static void __destroy_result_info(gpointer data) g_source_remove(info->timer); if (info->seq) free(info->seq); + if (info->fd > 0) + close(info->fd); free(info); } @@ -1389,6 +1391,7 @@ static void __pend_result_info(request_h req, int pid) const char *seq; struct timespec end; unsigned int interval; + int fd; if (pid <= 0) return; @@ -1402,10 +1405,11 @@ static void __pend_result_info(request_h req, int pid) clock_gettime(CLOCK_MONOTONIC, &end); interval = __get_timeout_interval(_request_get_start_time(req), &end); - info = __create_result_info(interval, pid, - _request_remove_fd(req), seq); + fd = _request_remove_fd(req); + info = __create_result_info(interval, pid, fd, seq); if (!info) { _E("Failed to create result info"); + close(fd); return; } @@ -1586,6 +1590,7 @@ static int __dispatch_app_result(request_h req) if (info) { res = aul_sock_send_bundle_with_fd(info->fd, pgid, kb, AUL_SOCK_NOREPLY); + info->fd = -1; __remove_result_info(info); __destroy_result_info(info); } else { diff --git a/src/modules/widget/src/amd_widget.c b/src/modules/widget/src/amd_widget.c index 7c740d54..140251ce 100644 --- a/src/modules/widget/src/amd_widget.c +++ b/src/modules/widget/src/amd_widget.c @@ -1135,7 +1135,7 @@ static int __send_running_info(widget_t *widget, int fd) if (b == NULL) { LOGE("Failed to create bundle"); aul_sock_send_raw_with_fd(fd, APP_GET_INFO_ERROR, - NULL, 0, AUL_SOCK_NOREPLY); + NULL, 0, AUL_SOCK_ASYNC); return -1; } @@ -1156,7 +1156,7 @@ static int __send_running_info(widget_t *widget, int fd) if (b_raw == NULL) { LOGE("Failed to encode bundle"); aul_sock_send_raw_with_fd(fd, APP_GET_INFO_ERROR, - NULL, 0, AUL_SOCK_NOREPLY); + NULL, 0, AUL_SOCK_ASYNC); bundle_free(b); return -1; }