Fix memory leak 78/126878/1
authorHaejeong Kim <backto.kim@samsung.com>
Tue, 25 Apr 2017 07:48:11 +0000 (16:48 +0900)
committerHaejeong Kim <backto.kim@samsung.com>
Tue, 25 Apr 2017 07:48:11 +0000 (16:48 +0900)
Change-Id: I89e3930e27a776e4a3972c7a13eac5789db7d5b3

src/media_util_private.c

index abb3e19..1b21512 100755 (executable)
@@ -24,7 +24,6 @@
 #include <media_util_private.h>
 #endif
 
-static char *g_old_path = NULL;
 #define TIZEN_USER_CONTENT_PATH  tzplatform_getenv(TZ_USER_CONTENT)
 
 int _media_util_check_file_exist(const char *path)
@@ -285,21 +284,22 @@ int _media_content_replace_path(const char *path, char *replace_path)
 #else
 
        int ret = MEDIA_CONTENT_ERROR_NONE;
+       char *old_internal_path =  NULL;
 
-       if (!STRING_VALID(g_old_path)) {
-               ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &g_old_path);
-               if (ret != STORAGE_ERROR_NONE) {
-                       media_content_error("storage_get_directory failed");
-                       return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
-               }
+       ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &old_internal_path);
+       if (ret != STORAGE_ERROR_NONE) {
+               media_content_error("storage_get_directory failed");
+               return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
        }
 
-       if (strncmp(path, g_old_path, strlen(g_old_path)) == 0) {
+       if (strncmp(path, old_internal_path, strlen(old_internal_path)) == 0) {
                media_content_sec_debug("Old path[%s]", path);
-               snprintf(replace_path, MAX_PATH_LEN, "%s%s", tzplatform_getenv(TZ_USER_CONTENT), path + strlen(g_old_path));
+               snprintf(replace_path, MAX_PATH_LEN, "%s%s", TIZEN_USER_CONTENT_PATH, path + strlen(old_internal_path));
        } else {
                snprintf(replace_path, MAX_PATH_LEN, "%s", path);
        }
+
+       SAFE_FREE(old_internal_path);
 #endif
 
        if (!STRING_VALID(replace_path)) {
@@ -317,21 +317,22 @@ int _media_content_rollback_path(const char *path, char *replace_path)
 #else
 
        int ret = MEDIA_CONTENT_ERROR_NONE;
+       char *old_internal_path =  NULL;
 
-       if (!STRING_VALID(g_old_path)) {
-               ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &g_old_path);
-               if (ret != STORAGE_ERROR_NONE) {
-                       media_content_error("storage_get_directory failed");
-                       return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
-               }
+       ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &old_internal_path);
+       if (ret != STORAGE_ERROR_NONE) {
+               media_content_error("storage_get_directory failed");
+               return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
        }
 
-       if (strncmp(path, tzplatform_getenv(TZ_USER_CONTENT), strlen(tzplatform_getenv(TZ_USER_CONTENT))) == 0) {
+       if (strncmp(path, TIZEN_USER_CONTENT_PATH, strlen(TIZEN_USER_CONTENT_PATH)) == 0) {
                media_content_sec_debug("new path[%s]", path);
-               snprintf(replace_path, MAX_PATH_LEN, "%s%s", g_old_path, path + strlen(tzplatform_getenv(TZ_USER_CONTENT)));
+               snprintf(replace_path, MAX_PATH_LEN, "%s%s", old_internal_path, path + strlen(TIZEN_USER_CONTENT_PATH));
        } else {
                snprintf(replace_path, MAX_PATH_LEN, "%s", path);
        }
+
+       SAFE_FREE(old_internal_path);
 #endif
 
        if (!STRING_VALID(replace_path)) {