diff --git a/daemon/src/audio/audiortp/audio_rtp_factory.cpp b/daemon/src/audio/audiortp/audio_rtp_factory.cpp index 2170b06e52a77e238fa1c4241ec4cc4bac363218..0eb046abe93aa751224924474ce5e8d2f89644a2 100644 --- a/daemon/src/audio/audiortp/audio_rtp_factory.cpp +++ b/daemon/src/audio/audiortp/audio_rtp_factory.cpp @@ -50,9 +50,11 @@ AudioRtpFactory::AudioRtpFactory(SIPCall *ca) : rtpSession_(NULL), AudioRtpFactory::~AudioRtpFactory() { + AudioSrtpSession* srtpSession = dynamic_cast<AudioSrtpSession*>(rtpSession_); + if (srtpSession) + srtpSession->deleteCryptoContexts(); + delete rtpSession_; - delete cachedLocalContext_; - delete cachedRemoteContext_; } void AudioRtpFactory::initConfig() diff --git a/daemon/src/audio/audiortp/audio_srtp_session.cpp b/daemon/src/audio/audiortp/audio_srtp_session.cpp index 38567d1b629cdbe7dbc29971401039429b9b3cc3..630d3ce94cd6dbe1eccf6479c3e76d321a8a7487 100644 --- a/daemon/src/audio/audiortp/audio_srtp_session.cpp +++ b/daemon/src/audio/audiortp/audio_srtp_session.cpp @@ -306,12 +306,23 @@ void AudioSrtpSession::initializeLocalCryptoContext() void AudioSrtpSession::restoreCryptoContext(ost::CryptoContext *localContext, ost::CryptoContext *remoteContext) { - delete remoteCryptoCtx_; - remoteCryptoCtx_ = remoteContext; - delete localCryptoCtx_; - localCryptoCtx_ = localContext; + if (remoteCryptoCtx_ != remoteContext) { + delete remoteCryptoCtx_; + remoteCryptoCtx_ = remoteContext; + } + if (localCryptoCtx_ != localContext) { + delete localCryptoCtx_; + localCryptoCtx_ = localContext; + } setInQueueCryptoContext(remoteCryptoCtx_); setOutQueueCryptoContext(localCryptoCtx_); } +void AudioSrtpSession::deleteCryptoContexts() +{ + delete remoteCryptoCtx_; + remoteCryptoCtx_ = 0; + delete localCryptoCtx_; + localCryptoCtx_ = 0; +} } diff --git a/daemon/src/audio/audiortp/audio_srtp_session.h b/daemon/src/audio/audiortp/audio_srtp_session.h index a84cfccc847b3ae4e1fc1827383e422289bcf9ee..733e0cfb229bbda1464f0cc8eb5722659f121aeb 100644 --- a/daemon/src/audio/audiortp/audio_srtp_session.h +++ b/daemon/src/audio/audiortp/audio_srtp_session.h @@ -101,6 +101,10 @@ class AudioSrtpSession : public AudioSymmetricRtpSession { */ void restoreCryptoContext(ost::CryptoContext *, ost::CryptoContext *); + /** + * Force deletion of the current crypto contexts. + */ + void deleteCryptoContexts(); private: NON_COPYABLE(AudioSrtpSession);