diff options
author | Myungki Lee <mk5004.lee@samsung.com> | 2016-02-23 20:06:21 +0900 |
---|---|---|
committer | Myungki Lee <mk5004.lee@samsung.com> | 2016-02-23 20:06:21 +0900 |
commit | c11209e06716eaa07a5fb169b8c9b81cc5b36ece (patch) | |
tree | 0cc9a44c89aa1f6fa1a8e30cfa58607feeb9eb05 | |
parent | 9a6ff490adb807c73e7f874ec35a91260a7bb69a (diff) | |
download | app-manager-c11209e06716eaa07a5fb169b8c9b81cc5b36ece.tar.gz app-manager-c11209e06716eaa07a5fb169b8c9b81cc5b36ece.tar.bz2 app-manager-c11209e06716eaa07a5fb169b8c9b81cc5b36ece.zip |
Fix error that may cause a segmentation fault
Change-Id: I9a42609c9ce89157d3fe9aa56d464052c7d2fd06
Signed-off-by: Myungki Lee <mk5004.lee@samsung.com>
-rw-r--r-- | src/app_context.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/app_context.c b/src/app_context.c index c6d5183..7d6878e 100644 --- a/src/app_context.c +++ b/src/app_context.c @@ -25,6 +25,7 @@ #include <aul.h> #include <dlog.h> +#include <pkgmgr-info.h> #include "app_context.h" #include "app_manager.h" @@ -246,7 +247,7 @@ static int app_context_create(const char *app_id, pid_t pid, char *pkg_id, app_s { app_context_h app_context_created; - if (app_id == NULL || pid <= 0 || app_context == NULL) + if (app_id == NULL || pid <= 0 || pkg_id == NULL || app_context == NULL) return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); app_context_created = calloc(1, sizeof(struct app_context_s)); @@ -452,16 +453,42 @@ static void app_context_pid_table_entry_destroyed_cb(void * data) app_context_destroy(app_context); } +static int app_context_get_pkgid_by_appid(const char *app_id, char **pkg_id) +{ + pkgmgrinfo_appinfo_h appinfo; + char *pkg_id_dup; + + if (app_id == NULL || pkg_id == NULL) + return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + + if (pkgmgrinfo_appinfo_get_usr_appinfo(app_id, getuid(), &appinfo) < 0) + return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, "fail to get appinfo"); + + if (pkgmgrinfo_appinfo_get_pkgid(appinfo, &pkg_id_dup) < 0) { + pkgmgrinfo_appinfo_destroy_appinfo(appinfo); + return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, "fail to get pkgid"); + } + + *pkg_id = strdup(pkg_id_dup); + + pkgmgrinfo_appinfo_destroy_appinfo(appinfo); + return APP_MANAGER_ERROR_NONE; +} + static int app_context_launched_event_cb(pid_t pid, const char *app_id, void *data) { app_context_h app_context = NULL; + char *pkg_id = NULL; if (pid < 0 || app_id == NULL) return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + if (app_context_get_pkgid_by_appid(app_id, &pkg_id) < 0) + return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, "no such pkg_id"); + app_context_lock_event_cb_context(); - if (app_context_create(app_id, pid, NULL, APP_STATE_UNDEFINED, false, &app_context) == APP_MANAGER_ERROR_NONE) { + if (app_context_create(app_id, pid, pkg_id, APP_STATE_UNDEFINED, false, &app_context) == APP_MANAGER_ERROR_NONE) { if (event_cb_context != NULL && event_cb_context->pid_table != NULL) { g_hash_table_insert(event_cb_context->pid_table, GINT_TO_POINTER(&(app_context->pid)), app_context); event_cb_context->callback(app_context, APP_CONTEXT_EVENT_LAUNCHED, event_cb_context->user_data); @@ -473,6 +500,7 @@ static int app_context_launched_event_cb(pid_t pid, const char *app_id, void *da app_context_unlock_event_cb_context(); + free(pkg_id); return 0; } |