Fix thread race caused double free issue. am: 5754b41c20
am: 09901f3bc9

Change-Id: Ied71f524dcb24439e121598beaec59029474cc4d