Fix incomplete refcounting and locking

These changes were supposed to be committed in the previous patch
"Better refcounting and locking" but seem to have gotten lost in a
rebase. It fixes a memory leak and some possible race conditions.

Change-Id: I54ca1e37500ec49756fe317cc6d6d03da9911501
5 files changed
tree: ca0e5d7f03ad7a06496c89c432220d5f08c0d80e
  1. include/
  2. libs/
  3. sample/