1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-19 23:41:51 +02:00

Do not leak Tag instances during metadata scan

This commit is contained in:
Uwe L. Korn 2014-09-19 18:43:00 +01:00
parent aefbe439d3
commit d6b4724264
4 changed files with 25 additions and 22 deletions

View File

@ -93,7 +93,7 @@ MetadataEditor::writeMetadata( bool closeDlg )
const char *encodedName = fileName.constData();
TagLib::FileRef f( encodedName );
Tomahawk::Tag* tag = Tomahawk::Tag::fromFile( f );
QSharedPointer<Tomahawk::Tag> tag( Tomahawk::Tag::fromFile( f ) );
if ( title() != m_result->track()->track() )
{

View File

@ -364,7 +364,7 @@ MusicScanner::readTags( const QFileInfo& fi )
int bitrate = 0;
int duration = 0;
Tag* tag = Tag::fromFile( f );
QSharedPointer<Tag> tag( Tag::fromFile( f ) );
if ( f.audioProperties() )
{
TagLib::AudioProperties *properties = f.audioProperties();

View File

@ -47,21 +47,23 @@
namespace Tomahawk
{
/*static*/ Tag* Tag::fromFile( const TagLib::FileRef &f )
QSharedPointer<Tag>
Tag::fromFile( const TagLib::FileRef &f )
{
Tag *t = 0;
QSharedPointer<Tag> t;
if( TagLib::Ogg::Vorbis::File *file =
dynamic_cast< TagLib::Ogg::Vorbis::File * >( f.file() ) )
{
if( file->tag() )
t = new OggTag( f.tag(), file->tag() );
t.reset( new OggTag( f.tag(), file->tag() ) );
}
else if( TagLib::Ogg::FLAC::File *file =
dynamic_cast< TagLib::Ogg::FLAC::File * >( f.file() ) )
{
if( file->tag() )
t = new OggTag( f.tag(), file->tag() );
t.reset( new OggTag( f.tag(), file->tag() ) );
}
#if TAGLIB_MAJOR_VERSION >= 1 && TAGLIB_MINOR_VERSION >= 9
else if ( TagLib::Ogg::Opus::File *file =
@ -69,7 +71,7 @@ namespace Tomahawk
{
if ( file->tag() )
{
t = new OggTag( f.tag(), file->tag() );
t.reset( new OggTag( f.tag(), file->tag() ) );
}
}
#endif
@ -77,61 +79,61 @@ namespace Tomahawk
dynamic_cast< TagLib::RIFF::AIFF::File * >( f.file() ) )
{
if( file->tag() )
t = new ID3v2Tag( f.tag(), file->tag() );
t.reset( new ID3v2Tag( f.tag(), file->tag() ) );
}
else if( TagLib::Ogg::Speex::File *file =
dynamic_cast< TagLib::Ogg::Speex::File * >( f.file() ) )
{
if( file->tag() )
t = new OggTag( f.tag(), file->tag() );
t.reset( new OggTag( f.tag(), file->tag() ) );
}
else if( TagLib::FLAC::File *file =
dynamic_cast< TagLib::FLAC::File * >( f.file() ) )
{
if( file->xiphComment() )
t = new OggTag( f.tag(), file->xiphComment() );
t.reset( new OggTag( f.tag(), file->xiphComment() ) );
else if( file->ID3v2Tag() )
t = new ID3v2Tag( f.tag(), file->ID3v2Tag() );
t.reset( new ID3v2Tag( f.tag(), file->ID3v2Tag() ) );
else if( file->ID3v1Tag() )
t = new ID3v1Tag( f.tag() );
t.reset( new ID3v1Tag( f.tag() ) );
}
else if( TagLib::MPEG::File *file =
dynamic_cast< TagLib::MPEG::File * >( f.file() ) )
{
if( file->ID3v2Tag() )
t = new ID3v2Tag( f.tag(), file->ID3v2Tag() );
t.reset( new ID3v2Tag( f.tag(), file->ID3v2Tag() ) );
else if( file->APETag() )
t = new APETag( f.tag(), file->APETag() );
t.reset( new APETag( f.tag(), file->APETag() ) );
else if( file->ID3v1Tag() )
t = new ID3v1Tag( f.tag() );
t.reset( new ID3v1Tag( f.tag() ) );
}
else if( TagLib::MP4::File *file =
dynamic_cast< TagLib::MP4::File * >( f.file() ) )
{
if( file->tag() )
t = new MP4Tag( f.tag(), file->tag() );
t.reset( new MP4Tag( f.tag(), file->tag() ) );
}
else if( TagLib::MPC::File *file =
dynamic_cast< TagLib::MPC::File * >( f.file() ) )
{
if( file->APETag() )
t = new APETag( f.tag(), file->APETag() );
t.reset( new APETag( f.tag(), file->APETag() ) );
else if( file->ID3v1Tag() )
t = new ID3v1Tag( f.tag() );
t.reset( new ID3v1Tag( f.tag() ) );
}
else if( TagLib::ASF::File *file =
dynamic_cast< TagLib::ASF::File * >( f.file() ) )
{
if( file->tag() )
t = new ASFTag( f.tag(), file->tag() );
t.reset( new ASFTag( f.tag(), file->tag() ) );
}
else if( TagLib::WavPack::File *file =
dynamic_cast< TagLib::WavPack::File * >( f.file() ) )
{
if( file->APETag() )
t = new APETag( f.tag(), file->APETag() );
t.reset( new APETag( f.tag(), file->APETag() ) );
else if( file->ID3v1Tag() )
t = new ID3v1Tag( f.tag() );
t.reset( new ID3v1Tag( f.tag() ) );
}
return t;

View File

@ -21,6 +21,7 @@
#include "DllMacro.h"
#include <QSharedPointer>
#include <QtCore/QString>
#include <taglib/tag.h>
@ -32,7 +33,7 @@ namespace Tomahawk
class DLLEXPORT Tag
{
public:
static Tag *fromFile( const TagLib::FileRef &f );
static QSharedPointer<Tag> fromFile( const TagLib::FileRef &f );
//getter-setters for common TagLib items
virtual QString title() const { return TStringToQString( m_tag->title() ).trimmed(); }