diff --git a/src/recorder/jamcontroller.cpp b/src/recorder/jamcontroller.cpp index 982b74cab3..164f6a43fd 100755 --- a/src/recorder/jamcontroller.cpp +++ b/src/recorder/jamcontroller.cpp @@ -30,7 +30,8 @@ CJamController::CJamController() : bRecorderInitialised ( false ), bEnableRecording ( false ), strRecordingDir ( "" ), - pthJamRecorder ( nullptr ) + pthJamRecorder ( nullptr ), + pJamRecorder ( nullptr ) { } @@ -85,11 +86,19 @@ void CJamController::SetRecordingDir ( QString newRecordingDir, // Hopefully changing recording directory will NOT happen during a long jam... emit EndRecorderThread(); pthJamRecorder->wait(); + delete pthJamRecorder; pthJamRecorder = nullptr; } if ( !newRecordingDir.isEmpty() ) { + if ( pJamRecorder != nullptr ) + { + // We have a reference to a CJamRecorder instance that should now have finished. + // Clean up the instance before replacing it. + delete pJamRecorder; + pJamRecorder = nullptr; + } pJamRecorder = new recorder::CJamRecorder ( newRecordingDir, iServerFrameSizeSamples ); strRecorderErrMsg = pJamRecorder->Init(); bRecorderInitialised = ( strRecorderErrMsg == QString::null ); diff --git a/src/recorder/jamrecorder.cpp b/src/recorder/jamrecorder.cpp index 859f8ab9c6..eb8edd6450 100755 --- a/src/recorder/jamrecorder.cpp +++ b/src/recorder/jamrecorder.cpp @@ -45,7 +45,8 @@ CJamClient::CJamClient(const qint64 frame, const int _numChannels, const QString startFrame (frame), numChannels (static_cast(_numChannels)), name (name), - address (address) + address (address), + out (nullptr) { // At this point we may not have much of a name QString fileName = ClientName() + "-" + QString::number(frame) + "-" + QString::number(_numChannels); @@ -88,8 +89,12 @@ void CJamClient::Frame(const QString _name, const CVector& pcm, int iSe */ void CJamClient::Disconnect() { - static_cast(out)->finalise(); - out = nullptr; + if (out) + { + static_cast(out)->finalise(); + delete out; + out = nullptr; + } wavFile->close(); @@ -134,6 +139,22 @@ CJamSession::CJamSession(QDir recordBaseDir) : vecptrJamClients.fill(nullptr); } +/** + * @brief CJamSession::~CJamSession + */ +CJamSession::~CJamSession() +{ + // free up any active jamClientConnections + for (int i = 0; i < jamClientConnections.count(); i++ ) + { + if ( jamClientConnections[i] ) + { + delete jamClientConnections[i]; + jamClientConnections[i] = nullptr; + } + } +} + /** * @brief CJamSession::DisconnectClient Capture details of the departing client's connection * @param iChID the channel id of the client that disconnected diff --git a/src/recorder/jamrecorder.h b/src/recorder/jamrecorder.h index a42fe0c457..340e593821 100755 --- a/src/recorder/jamrecorder.h +++ b/src/recorder/jamrecorder.h @@ -108,6 +108,8 @@ class CJamSession : public QObject CJamSession(QDir recordBaseDir); + virtual ~CJamSession(); + void Frame(const int iChID, const QString name, const CHostAddress address, const int numAudioChannels, const CVector data, int iServerFrameSizeSamples); void End();