Fix use after free issue am: bf0d7ca7e4 am: 2688c3b10f am: 594894eaed

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/av/+/12038058

Change-Id: Ia5fb725a19ad8abd1e23b1499a8fd1a33733a426