Fix bug related import playlist 62/89962/1
authorMinje Ahn <minje.ahn@samsung.com>
Wed, 28 Sep 2016 02:14:24 +0000 (11:14 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Wed, 28 Sep 2016 02:14:24 +0000 (11:14 +0900)
Change-Id: Ifb816b8cc441d41ba924ee033c61c0bd5abe0a79
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
packaging/capi-content-media-content.spec
src/media_db.c
src/media_playlist.c

index 02005f7..584942b 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-content-media-content
 Summary:    A Media content library in Tizen Native API
-Version:    0.2.84
+Version:    0.2.85
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 3dda484..d6ae261 100755 (executable)
@@ -674,6 +674,7 @@ int _media_db_get_playlist(filter_h filter, media_playlist_cb callback, void *us
 
        attr = _content_get_attirbute_handle();
        memset(select_query, 0x00, sizeof(select_query));
+       memset(repl_path, 0x00, sizeof(repl_path));
 
        if (!SAFE_STRLCPY(select_query, SELECT_PLAYLIST_LIST, sizeof(select_query))) {
                media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
index fd21668..bc067b1 100755 (executable)
@@ -231,7 +231,6 @@ static int __media_playlist_import_item_from_file(const char* playlist_path, cha
        int current_index = 0;
        int current_max_size = PLAYLIST_ARRAY_SIZE;
        int tmp_str_len = 0;
-       char *buf = NULL;
        char *tmp_buf = NULL;
        char *tmp_str = NULL;
        char repl_item[MAX_QUERY_SIZE] = {0, };
@@ -254,54 +253,26 @@ static int __media_playlist_import_item_from_file(const char* playlist_path, cha
                return MEDIA_CONTENT_ERROR_NONE;
        }
 
-       if (file_size > 0)
-               buf = malloc(file_size + 1);
-
-       if (buf == NULL) {
-               media_content_error("Out of Memory");
-               fclose(fp);
-               return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
-       }
-
-       tmp_buf = buf;
-
-       if (fread(buf, file_size, 1, fp) != 1) {
-               fclose(fp);
-               SAFE_FREE(buf);
-               media_content_stderror("fread fail");
-               return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
-       }
-       buf[file_size] = 0;
-       fclose(fp);
-
        *item_list = calloc(current_max_size, sizeof(char*));
-       tmp_str = malloc(MAX_TMP_STR);
+       tmp_str = malloc(MAX_QUERY_SIZE);
        if (tmp_str == NULL || *item_list == NULL) {
+               fclose(fp);
                SAFE_FREE(*item_list);
-               SAFE_FREE(buf);
                SAFE_FREE(tmp_str);
                media_content_error("Out of Memory");
                return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
        }
+       memset(tmp_str, 0, sizeof(MAX_QUERY_SIZE));
 
-       char format[25];
-       snprintf(format, 25, "%%%d[^\n]", MAX_TMP_STR - 1);
-
-       while ((sscanf(tmp_buf, format, tmp_str) == 1) || (*tmp_buf == '\n')) {
-               if (*tmp_buf == '\n') {
-                       tmp_buf += 1;
-
-                       if (tmp_buf < (buf + file_size))
-                               continue;
-                       else
-                               break;
-               }
-
+       while (fgets(tmp_str, MAX_QUERY_SIZE, fp) != NULL) {
                memset(repl_item, 0, sizeof(repl_item));
                _media_content_replace_path(tmp_str, repl_item);
                tmp_str_len = strlen(repl_item);
+               if (repl_item[tmp_str_len - 1] == '\n')
+                       repl_item[tmp_str_len - 1] = '\0';
+
                SAFE_FREE(tmp_str);
-               tmp_str = strndup(repl_item, tmp_str_len);
+               tmp_str = strndup(repl_item, strlen(repl_item));
 
                if (tmp_str[0] != '#') {
                        if (!(current_index < (current_max_size - 1))) {
@@ -309,9 +280,9 @@ static int __media_playlist_import_item_from_file(const char* playlist_path, cha
                                char **tmp_ptr = calloc(current_max_size, sizeof(char*));
                                if (tmp_ptr == NULL) {
                                        __media_playlist_destroy_import_item(*item_list, current_index);
-                                       SAFE_FREE(buf);
                                        SAFE_FREE(tmp_str);
                                        media_content_error("Out of Memory");
+                                       fclose(fp);
                                        return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
                                }
                                memmove(tmp_ptr, *item_list, sizeof(char*) * current_index);
@@ -322,9 +293,9 @@ static int __media_playlist_import_item_from_file(const char* playlist_path, cha
                        (*item_list)[current_index] = malloc(tmp_str_len + 1);
                        if ((*item_list)[current_index] == NULL) {
                                __media_playlist_destroy_import_item(*item_list, current_index);
-                               SAFE_FREE(buf);
                                SAFE_FREE(tmp_str);
                                media_content_error("Out of Memory");
+                               fclose(fp);
                                return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
                        }
                        memset((*item_list)[current_index], 0, tmp_str_len + 1);
@@ -337,9 +308,8 @@ static int __media_playlist_import_item_from_file(const char* playlist_path, cha
        }
 
        *item_count = current_index;
-
-       SAFE_FREE(buf);
        SAFE_FREE(tmp_str);
+       fclose(fp);
 
        return MEDIA_CONTENT_ERROR_NONE;
 }