Skip to content

Commit 7c1a0e8

Browse files
ARRISEOS-48521 OCDM: protect against double-delete
There are some scenarios where OCDM::Deinitialize seems to be run more than once in parallel (likely on Thunder shutdown). The change protects against double-release/use-after-free bugs.
1 parent 66f1f7a commit 7c1a0e8

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

OpenCDMi/OCDM.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ namespace Plugin {
109109
ForceLinkingOfOpenCDM();
110110
#endif
111111

112+
std::lock_guard<std::recursive_mutex> lock {_serviceInitMutex};
112113
string message;
113114

114115
ASSERT(service != nullptr);
@@ -157,9 +158,12 @@ namespace Plugin {
157158

158159
/*virtual*/ void OCDM::Deinitialize(PluginHost::IShell* service)
159160
{
161+
std::lock_guard<std::recursive_mutex> lock {_serviceInitMutex};
160162
ASSERT(_service == service);
161163

162-
_service->Unregister(&_notification);
164+
if (_service == nullptr) {
165+
TRACE(Trace::Error, (_T("OCDM::Deinitialize called with null _service; will be skipped. %d"), __LINE__));
166+
}
163167

164168
if(_opencdmi != nullptr) {
165169

@@ -169,7 +173,7 @@ namespace Plugin {
169173
}
170174

171175
_opencdmi->Unregister(&_notification);
172-
_opencdmi->Deinitialize(service);
176+
_opencdmi->Deinitialize(_service);
173177
RPC::IRemoteConnection* connection(_service->RemoteConnection(_connectionId));
174178

175179
UnregisterAll();
@@ -193,7 +197,7 @@ namespace Plugin {
193197
}
194198
}
195199

196-
PluginHost::ISubSystem* subSystem = service->SubSystems();
200+
PluginHost::ISubSystem* subSystem = _service->SubSystems();
197201

198202
if (subSystem != nullptr) {
199203
if(subSystem->IsActive(PluginHost::ISubSystem::DECRYPTION) == true) {

OpenCDMi/OCDM.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#ifndef __OPENCDMI_H
2121
#define __OPENCDMI_H
2222

23+
#include <mutex>
24+
2325
#include "Module.h"
2426
#include <interfaces/IContentDecryption.h>
2527
#include <interfaces/IMemory.h>
@@ -225,6 +227,7 @@ namespace Plugin {
225227
Exchange::IContentDecryption* _opencdmi;
226228
Exchange::IMemory* _memory;
227229
Core::Sink<Notification> _notification;
230+
std::recursive_mutex _serviceInitMutex;
228231
};
229232
} //namespace Plugin
230233

0 commit comments

Comments
 (0)