From fd56f934487062fe54ef29b3c40749f0d97858f3 Mon Sep 17 00:00:00 2001 From: hj kim Date: Wed, 6 May 2020 16:47:24 +0900 Subject: [PATCH] Improve metadata_editor_create() and Bug fix of metadata_editor_destroy() 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 | 54 ++++------------------------------------- 1 file changed, 5 insertions(+), 49 deletions(-) diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 730f015..205c867 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -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(" with address %p will be freed", metadata); - delete _metadata; + g_free(_metadata); return METADATA_EDITOR_ERROR_NONE; } -- 2.34.1