Address concurrency failures between calls to decrypt and periodic timer

[ http://go/wvgerrit/50341 ]

The shared_ptr implementation was taken from a google3 implementation.
Updates to the reference counter needed to be atomic and were
platform dependent in the original code. These were not carried
over to this codebase. Race conditions between calls to decrypt and
the periodic timer, led to incorrect reference count values.
CdmSession objects were then destructed while references to
them still existed. Segfaults occurred when they were referenced.

Bug: 79431096

Test: WV unit/integration tests, GTS GtsMediaTestCases tests and
      24 hours of continuous Netflix playback.

Change-Id: I6008ddba869efcc58972e5ea8644a204f91410ab
This commit is contained in:
Rahul Frias
2018-05-13 15:54:25 -07:00
parent 0163607fa3
commit dcab2b1355
2 changed files with 12 additions and 0 deletions

View File

@@ -12,9 +12,17 @@
#include <stddef.h>
#include <memory>
#include "lock.h"
#include "wv_cdm_types.h"
namespace wvcdm {
extern Lock shared_ptr_ref_count_lock_;
} // namespace wvcdm
namespace {
bool Barrier_AtomicIncrement(volatile uint32_t* ptr, uint32_t value) {
*ptr += value;
return *ptr;
@@ -25,10 +33,12 @@ bool NoBarrier_AtomicIncrement(volatile uint32_t* ptr, uint32_t value) {
}
inline bool RefCountDec(volatile uint32_t *ptr) {
wvcdm::AutoLock auto_lock(wvcdm::shared_ptr_ref_count_lock_);
return Barrier_AtomicIncrement(ptr, -1) != 0;
}
inline void RefCountInc(volatile uint32_t *ptr) {
wvcdm::AutoLock auto_lock(wvcdm::shared_ptr_ref_count_lock_);
NoBarrier_AtomicIncrement(ptr, 1);
}

View File

@@ -30,6 +30,8 @@ const size_t kUsageReportsPerRequest = 1;
namespace wvcdm {
Lock shared_ptr_ref_count_lock_;
class UsagePropertySet : public CdmClientPropertySet {
public:
UsagePropertySet() {}