summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafal Krypa <r.krypa@samsung.com>2016-03-14 14:17:18 +0100
committerRafal Krypa <r.krypa@samsung.com>2016-03-14 14:21:43 +0100
commitcc059948b58bdfebf7e084bc64a97b617164c1df (patch)
treeedf2a523478f32af454962696ed285674cb1adb1
parent2a9b7604632310069a140fc11ff0950111c31cd0 (diff)
downloadsecurity-manager-cc059948b58bdfebf7e084bc64a97b617164c1df.tar.gz
security-manager-cc059948b58bdfebf7e084bc64a97b617164c1df.tar.bz2
security-manager-cc059948b58bdfebf7e084bc64a97b617164c1df.zip
Change-Id: Iefa723380df60af802e33bbeb95d4d0ebe543444 Signed-off-by: Rafal Krypa <r.krypa@samsung.com>
-rw-r--r--src/common/service_impl.cpp22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/common/service_impl.cpp b/src/common/service_impl.cpp
index a9a624e4..2c09ec1f 100644
--- a/src/common/service_impl.cpp
+++ b/src/common/service_impl.cpp
@@ -214,25 +214,23 @@ bool ServiceImpl::getUserAppDir(const uid_t &uid, std::string &userAppDir)
if (tzplatform_context_create(&tz_ctx))
return false;
- if (tzplatform_context_set_user(tz_ctx, uid)) {
- tzplatform_context_destroy(tz_ctx);
- tz_ctx = nullptr;
+ std::unique_ptr<struct tzplatform_context, decltype(tzplatform_context_destroy)*> tz_ctxPtr(
+ tz_ctx, &tzplatform_context_destroy);
+
+ if (tzplatform_context_set_user(tz_ctxPtr.get(), uid))
return false;
- }
enum tzplatform_variable id =
(uid == getGlobalUserId()) ? TZ_SYS_RW_APP : TZ_USER_APP;
- const char *appDir = tzplatform_context_getenv(tz_ctx, id);
- if (!appDir) {
- tzplatform_context_destroy(tz_ctx);
- tz_ctx = nullptr;
+ const char *appDir = tzplatform_context_getenv(tz_ctxPtr.get(), id);
+ if (!appDir)
return false;
- }
- userAppDir = appDir;
+ std::unique_ptr<char, decltype(free)*> real_pathPtr(realpath(appDir, NULL), free);
+ if (!real_pathPtr.get())
+ return false;
- tzplatform_context_destroy(tz_ctx);
- tz_ctx = nullptr;
+ userAppDir.assign(real_pathPtr.get());
return true;
}