Fix EIR UUID cache crash

Tag: #stability
Test: atest BluetoothInstrumentationTests
Test: avatar
Bug: 243380633
Bug: 242350646
Change-Id: I86c9058995efb22029f2f7840c4b9d0052a6230b
diff --git a/system/btif/src/btif_dm.cc b/system/btif/src/btif_dm.cc
index b6e6eac..ee6c2f2 100644
--- a/system/btif/src/btif_dm.cc
+++ b/system/btif/src/btif_dm.cc
@@ -1466,6 +1466,7 @@
               property_value.insert(property_value.end(), uuid_128bit.begin(),
                                     uuid_128bit.end());
             }
+            eir_uuids_cache.erase(uuids_iter);
           }
           if (num_eir_uuids > 0) {
             prop.val = (void*)property_value.data();
@@ -1475,7 +1476,6 @@
             prop.val = &uuid;
             prop.len = Uuid::kNumBytes128;
           }
-          eir_uuids_cache.erase(uuids_iter);
         }
         // Both SDP and bonding are done, clear pairing control block in case
         // it is not already cleared