fix race condition that can cause a use after free
am: 59485525a6

Change-Id: I42d7ee49dc3dcbd9d5d4a86fc9d018ff6c29534d