Improve metadata_editor_create() and Bug fix of metadata_editor_destroy() 43/232543/8
authorhj kim <backto.kim@samsung.com>
Wed, 6 May 2020 07:47:24 +0000 (16:47 +0900)
committerhj kim <backto.kim@samsung.com>
Wed, 6 May 2020 09:18:58 +0000 (09:18 +0000)
filetype can be METADATA_EDITOR_FORMAT_NOTYPE if user only create handle with metadata_editor_create() without setting path.

Change-Id: Ie4d3784da64274d1b5ba127073356f492c761b16

src/metadata_editor.cpp

index 730f015..205c867 100755 (executable)
@@ -779,8 +779,7 @@ int __metadata_editor_get_picture_info(const char *path, void **picture, int *si
 extern "C" int metadata_editor_create(metadata_editor_h *metadata) {
        metadata_editor_retvm_if(metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid metadata");
 
-       metadata_editor_s *_metadata = new metadata_editor_s;           // Allocate a structure for handler
-       metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+       metadata_editor_s *_metadata = g_new0(metadata_editor_s, 1);
 
        _metadata->file = NULL;
        _metadata->filetype = METADATA_EDITOR_FORMAT_NOTYPE;                    // Specify file type out of range
@@ -1833,58 +1832,15 @@ extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int in
        }
 }
 
-// *** This function is used to free memory that was allocated with metadata_editor_create(...) and metadata_editor_set_path(...) functions *** //
 extern "C" int metadata_editor_destroy(metadata_editor_h metadata) {
        metadata_editor_s *_metadata = (metadata_editor_s*)metadata;
+
        metadata_editor_retvm_if(!_metadata, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid metadata");
 
-       switch (_metadata->filetype) {
-               case METADATA_EDITOR_FORMAT_MP3: {
-                       // Bring the pointer to actual file type
-                       TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file;
-                       metadata_editor_info("file free [%p]", _metadata->file);
-                       delete _file;
-                       break;
-               }
-               case METADATA_EDITOR_FORMAT_MP4: {
-                       TagLib::MP4::File* _file = (TagLib::MP4::File*)_metadata->file;
-                       metadata_editor_info("file free [%p]", _metadata->file);
-                       delete _file;
-                       break;
-               }
-#if 0
-               case METADATA_EDITOR_FORMAT_FLAC: {
-                       TagLib::FLAC::File* _file = (TagLib::FLAC::File*)_metadata->file;
-                       metadata_editor_info("file free [%p]", _metadata->file);
-                       delete _file;
-                       break;
-               }
-               case METADATA_EDITOR_FORMAT_OGG_VORBIS: {
-                       TagLib::Ogg::Vorbis::File* _file = (TagLib::Ogg::Vorbis::File*)_metadata->file;
-                       metadata_editor_info("file free [%p]", _metadata->file);
-                       delete _file;
-                       break;
-               }
-               case METADATA_EDITOR_FORMAT_OGG_FLAC: {
-                       TagLib::Ogg::FLAC::File* _file = (TagLib::Ogg::FLAC::File*)_metadata->file;
-                       metadata_editor_info("file free [%p]", _metadata->file);
-                       delete _file;
-                       break;
-               }
-               case METADATA_EDITOR_FORMAT_WAV: {
-                       TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file;
-                       metadata_editor_info("file free [%p]", _metadata->file);
-                       delete _file;
-                       break;
-               }
-#endif
-               default:
-                       metadata_editor_error("Wrong file type");
-                       return METADATA_EDITOR_ERROR_INVALID_PARAMETER;
-       }
+       if (_metadata->file)
+               delete _metadata->file;
 
-       metadata_editor_info("<metadata_editor_s> with address %p will be freed", metadata);
-       delete _metadata;
+       g_free(_metadata);
 
        return METADATA_EDITOR_ERROR_NONE;
 }