Fix some memory leaks (#3779)
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
#ifndef PLUGINFACTORY_H
|
||||
#define PLUGINFACTORY_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QList>
|
||||
|
||||
@@ -39,14 +41,15 @@ public:
|
||||
struct PluginInfo
|
||||
{
|
||||
PluginInfo() : library(nullptr), descriptor(nullptr) {}
|
||||
|
||||
const QString name() const;
|
||||
QFileInfo file;
|
||||
QLibrary* library;
|
||||
std::shared_ptr<QLibrary> library;
|
||||
Plugin::Descriptor* descriptor;
|
||||
|
||||
bool isNull() const {return library == 0;}
|
||||
bool isNull() const {return ! library;}
|
||||
};
|
||||
typedef QList<PluginInfo*> PluginInfoList;
|
||||
typedef QList<PluginInfo> PluginInfoList;
|
||||
typedef QMultiMap<Plugin::PluginTypes, Plugin::Descriptor*> DescriptorMap;
|
||||
|
||||
PluginFactory();
|
||||
@@ -80,11 +83,11 @@ public slots:
|
||||
private:
|
||||
DescriptorMap m_descriptors;
|
||||
PluginInfoList m_pluginInfos;
|
||||
QMap<QString, PluginInfo*> m_pluginByExt;
|
||||
QMap<QString, PluginInfo> m_pluginByExt;
|
||||
|
||||
QHash<QString, QString> m_errors;
|
||||
|
||||
static PluginFactory* s_instance;
|
||||
static std::unique_ptr<PluginFactory> s_instance;
|
||||
};
|
||||
|
||||
#define pluginFactory PluginFactory::instance()
|
||||
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
void clearErrors();
|
||||
void collectError( const QString error );
|
||||
bool hasErrors();
|
||||
QString* errorSummary();
|
||||
QString errorSummary();
|
||||
|
||||
class PlayPos : public MidiTime
|
||||
{
|
||||
@@ -359,7 +359,7 @@ private:
|
||||
|
||||
bool m_loadingProject;
|
||||
|
||||
QList<QString> * m_errors;
|
||||
QStringList m_errors;
|
||||
|
||||
PlayModes m_playMode;
|
||||
PlayPos m_playPos[Mode_Count];
|
||||
|
||||
@@ -42,7 +42,7 @@ qint64 qHash(const QFileInfo& fi)
|
||||
return qHash(fi.absoluteFilePath());
|
||||
}
|
||||
|
||||
PluginFactory* PluginFactory::s_instance = nullptr;
|
||||
std::unique_ptr<PluginFactory> PluginFactory::s_instance;
|
||||
|
||||
PluginFactory::PluginFactory()
|
||||
{
|
||||
@@ -87,9 +87,9 @@ PluginFactory::~PluginFactory()
|
||||
PluginFactory* PluginFactory::instance()
|
||||
{
|
||||
if (s_instance == nullptr)
|
||||
s_instance = new PluginFactory();
|
||||
s_instance.reset(new PluginFactory());
|
||||
|
||||
return s_instance;
|
||||
return s_instance.get();
|
||||
}
|
||||
|
||||
const Plugin::DescriptorList PluginFactory::descriptors() const
|
||||
@@ -109,16 +109,15 @@ const PluginFactory::PluginInfoList& PluginFactory::pluginInfos() const
|
||||
|
||||
const PluginFactory::PluginInfo PluginFactory::pluginSupportingExtension(const QString& ext)
|
||||
{
|
||||
PluginInfo* info = m_pluginByExt.value(ext, nullptr);
|
||||
return info == nullptr ? PluginInfo() : *info;
|
||||
return m_pluginByExt.value(ext, PluginInfo());
|
||||
}
|
||||
|
||||
const PluginFactory::PluginInfo PluginFactory::pluginInfo(const char* name) const
|
||||
{
|
||||
for (const PluginInfo* info : m_pluginInfos)
|
||||
for (const PluginInfo& info : m_pluginInfos)
|
||||
{
|
||||
if (qstrcmp(info->descriptor->name, name) == 0)
|
||||
return *info;
|
||||
if (qstrcmp(info.descriptor->name, name) == 0)
|
||||
return info;
|
||||
}
|
||||
return PluginInfo();
|
||||
}
|
||||
@@ -150,7 +149,7 @@ void PluginFactory::discoverPlugins()
|
||||
|
||||
for (const QFileInfo& file : files)
|
||||
{
|
||||
QLibrary* library = new QLibrary(file.absoluteFilePath());
|
||||
auto library = std::make_shared<QLibrary>(file.absoluteFilePath());
|
||||
|
||||
if (! library->load()) {
|
||||
m_errors[file.baseName()] = library->errorString();
|
||||
@@ -167,7 +166,7 @@ void PluginFactory::discoverPlugins()
|
||||
descriptorName = descriptorName.mid(3);
|
||||
}
|
||||
|
||||
Plugin::Descriptor* pluginDescriptor = (Plugin::Descriptor*) library->resolve(descriptorName.toUtf8().constData());
|
||||
Plugin::Descriptor* pluginDescriptor = reinterpret_cast<Plugin::Descriptor*>(library->resolve(descriptorName.toUtf8().constData()));
|
||||
if(pluginDescriptor == nullptr)
|
||||
{
|
||||
qWarning() << qApp->translate("PluginFactory", "LMMS plugin %1 does not have a plugin descriptor named %2!").
|
||||
@@ -175,26 +174,20 @@ void PluginFactory::discoverPlugins()
|
||||
continue;
|
||||
}
|
||||
|
||||
PluginInfo* info = new PluginInfo;
|
||||
info->file = file;
|
||||
info->library = library;
|
||||
info->descriptor = pluginDescriptor;
|
||||
PluginInfo info;
|
||||
info.file = file;
|
||||
info.library = library;
|
||||
info.descriptor = pluginDescriptor;
|
||||
pluginInfos << info;
|
||||
|
||||
for (const QString& ext : QString(info->descriptor->supportedFileTypes).split(','))
|
||||
for (const QString& ext : QString(info.descriptor->supportedFileTypes).split(','))
|
||||
{
|
||||
m_pluginByExt.insert(ext, info);
|
||||
}
|
||||
|
||||
descriptors.insert(info->descriptor->type, info->descriptor);
|
||||
descriptors.insert(info.descriptor->type, info.descriptor);
|
||||
}
|
||||
|
||||
|
||||
for (PluginInfo* info : m_pluginInfos)
|
||||
{
|
||||
delete info->library;
|
||||
delete info;
|
||||
}
|
||||
m_pluginInfos = pluginInfos;
|
||||
m_descriptors = descriptors;
|
||||
}
|
||||
|
||||
@@ -86,7 +86,6 @@ Song::Song() :
|
||||
m_playing( false ),
|
||||
m_paused( false ),
|
||||
m_loadingProject( false ),
|
||||
m_errors( new QList<QString>() ),
|
||||
m_playMode( Mode_None ),
|
||||
m_length( 0 ),
|
||||
m_patternToPlay( NULL ),
|
||||
@@ -1138,12 +1137,12 @@ void Song::loadProject( const QString & fileName )
|
||||
{
|
||||
if ( gui )
|
||||
{
|
||||
QMessageBox::warning( NULL, tr("LMMS Error report"), *errorSummary(),
|
||||
QMessageBox::warning( NULL, tr("LMMS Error report"), errorSummary(),
|
||||
QMessageBox::Ok );
|
||||
}
|
||||
else
|
||||
{
|
||||
QTextStream(stderr) << *Engine::getSong()->errorSummary() << endl;
|
||||
QTextStream(stderr) << Engine::getSong()->errorSummary() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1515,36 +1514,31 @@ void Song::removeController( Controller * controller )
|
||||
|
||||
void Song::clearErrors()
|
||||
{
|
||||
m_errors->clear();
|
||||
m_errors.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Song::collectError( const QString error )
|
||||
{
|
||||
m_errors->append( error );
|
||||
m_errors.append( error );
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Song::hasErrors()
|
||||
{
|
||||
return ( m_errors->length() > 0 );
|
||||
return ( m_errors.length() > 0 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
QString* Song::errorSummary()
|
||||
QString Song::errorSummary()
|
||||
{
|
||||
QString* errors = new QString();
|
||||
QString errors = m_errors.join("\n") + '\n';
|
||||
|
||||
for ( int i = 0 ; i < m_errors->length() ; i++ )
|
||||
{
|
||||
errors->append( m_errors->value( i ) + "\n" );
|
||||
}
|
||||
|
||||
errors->prepend( "\n\n" );
|
||||
errors->prepend( tr( "The following errors occured while loading: " ) );
|
||||
errors.prepend( "\n\n" );
|
||||
errors.prepend( tr( "The following errors occured while loading: " ) );
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ SongEditor::SongEditor( Song * song ) :
|
||||
m_smoothScroll( ConfigManager::inst()->value( "ui", "smoothscroll" ).toInt() ),
|
||||
m_mode(DrawMode)
|
||||
{
|
||||
m_zoomingModel->setParent(this);
|
||||
// create time-line
|
||||
int widgetTotal = ConfigManager::inst()->value( "ui",
|
||||
"compacttrackbuttons" ).toInt()==1 ?
|
||||
|
||||
Reference in New Issue
Block a user