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

Change-Id: I5bf330035a01e4f94235561342bc942142d9f007