Fixed possible memory-leak in case that the processing thread failed to start.

This commit is contained in:
LoRd_MuldeR 2018-04-15 01:06:02 +02:00
parent 6cbb086a1c
commit 23ccdd21a0
2 changed files with 19 additions and 15 deletions

View File

@ -554,20 +554,22 @@ void ProcessingDialog::startNextJob(void)
m_currentFile++; m_currentFile++;
m_runningThreads++; m_runningThreads++;
AudioFileModel currentFile = updateMetaInfo(m_pendingJobs.takeFirst()); //Fetch next file
AudioFileModel currentFile = m_pendingJobs.takeFirst();
updateMetaInfo(currentFile);
//Create encoder instance //Create encoder instance
AbstractEncoder *encoder = EncoderRegistry::createInstance(m_settings->compressionEncoder(), m_settings); AbstractEncoder *encoder = EncoderRegistry::createInstance(m_settings->compressionEncoder(), m_settings);
//Create processing thread //Create processing thread
ProcessThread *thread = new ProcessThread QScopedPointer<ProcessThread> thread(new ProcessThread
( (
currentFile, currentFile,
(m_settings->outputToSourceDir() ? QFileInfo(currentFile.filePath()).absolutePath() : m_settings->outputDir()), (m_settings->outputToSourceDir() ? QFileInfo(currentFile.filePath()).absolutePath() : m_settings->outputDir()),
m_tempFolder, m_tempFolder,
encoder, encoder,
m_settings->prependRelativeSourcePath() && (!m_settings->outputToSourceDir()) m_settings->prependRelativeSourcePath() && (!m_settings->outputToSourceDir())
); ));
//Add audio filters //Add audio filters
if(m_settings->forceStereoDownmix()) if(m_settings->forceStereoDownmix())
@ -618,15 +620,16 @@ void ProcessingDialog::startNextJob(void)
thread->setKeepDateTime(m_settings->keepOriginalDataTime()); thread->setKeepDateTime(m_settings->keepOriginalDataTime());
} }
//Save job UUID
m_allJobs.append(thread->getId()); m_allJobs.append(thread->getId());
//Connect thread signals //Connect thread signals
connect(thread, SIGNAL(processFinished()), this, SLOT(doneEncoding()), Qt::QueuedConnection); connect(thread.data(), SIGNAL(processFinished()), this, SLOT(doneEncoding()), Qt::QueuedConnection);
connect(thread, SIGNAL(processStateInitialized(QUuid,QString,QString,int)), m_progressModel.data(), SLOT(addJob(QUuid,QString,QString,int)), Qt::QueuedConnection); connect(thread.data(), SIGNAL(processStateInitialized(QUuid,QString,QString,int)), m_progressModel.data(), SLOT(addJob(QUuid,QString,QString,int)), Qt::QueuedConnection);
connect(thread, SIGNAL(processStateChanged(QUuid,QString,int)), m_progressModel.data(), SLOT(updateJob(QUuid,QString,int)), Qt::QueuedConnection); connect(thread.data(), SIGNAL(processStateChanged(QUuid,QString,int)), m_progressModel.data(), SLOT(updateJob(QUuid,QString,int)), Qt::QueuedConnection);
connect(thread, SIGNAL(processStateFinished(QUuid,QString,int)), this, SLOT(processFinished(QUuid,QString,int)), Qt::QueuedConnection); connect(thread.data(), SIGNAL(processStateFinished(QUuid,QString,int)), this, SLOT(processFinished(QUuid,QString,int)), Qt::QueuedConnection);
connect(thread, SIGNAL(processMessageLogged(QUuid,QString)), m_progressModel.data(), SLOT(appendToLog(QUuid,QString)), Qt::QueuedConnection); connect(thread.data(), SIGNAL(processMessageLogged(QUuid,QString)), m_progressModel.data(), SLOT(appendToLog(QUuid,QString)), Qt::QueuedConnection);
connect(this, SIGNAL(abortRunningTasks()), thread, SLOT(abort()), Qt::DirectConnection); connect(this, SIGNAL(abortRunningTasks()), thread.data(), SLOT(abort()), Qt::DirectConnection);
//Initialize thread object //Initialize thread object
if(!thread->init()) if(!thread->init())
@ -637,8 +640,11 @@ void ProcessingDialog::startNextJob(void)
//Give it a go! //Give it a go!
if(!thread->start(m_threadPool.data())) if(!thread->start(m_threadPool.data()))
{ {
qWarning("Job failed to start or file was skipped!"); qWarning("Job failed to start or the file was skipped!");
return;
} }
thread.take(); //will be auto-deleted by QThreadPool!
} }
void ProcessingDialog::abortEncoding(bool force) void ProcessingDialog::abortEncoding(bool force)
@ -1045,12 +1051,12 @@ void ProcessingDialog::writePlayList(void)
} }
} }
AudioFileModel ProcessingDialog::updateMetaInfo(AudioFileModel &audioFile) void ProcessingDialog::updateMetaInfo(AudioFileModel &audioFile)
{ {
if(!m_settings->writeMetaTags()) if(!m_settings->writeMetaTags())
{ {
audioFile.metaInfo().reset(); audioFile.metaInfo().reset();
return audioFile; return;
} }
audioFile.metaInfo().update(*m_metaInfo, true); audioFile.metaInfo().update(*m_metaInfo, true);
@ -1059,8 +1065,6 @@ AudioFileModel ProcessingDialog::updateMetaInfo(AudioFileModel &audioFile)
{ {
audioFile.metaInfo().setPosition(m_currentFile); audioFile.metaInfo().setPosition(m_currentFile);
} }
return audioFile;
} }
void ProcessingDialog::systemTrayActivated(QSystemTrayIcon::ActivationReason reason) void ProcessingDialog::systemTrayActivated(QSystemTrayIcon::ActivationReason reason)

View File

@ -110,7 +110,7 @@ private:
Ui::ProcessingDialog *ui; //for Qt UIC Ui::ProcessingDialog *ui; //for Qt UIC
QThreadPool *createThreadPool(void); QThreadPool *createThreadPool(void);
AudioFileModel updateMetaInfo(AudioFileModel &audioFile); void updateMetaInfo(AudioFileModel &audioFile);
void writePlayList(void); void writePlayList(void);
bool shutdownComputer(void); bool shutdownComputer(void);