GAP: Set service_id before calling gap_release_ccb

Calling gap_release_ccb with a service_id == 0, which in turn
calls BTM_SecClrService with an ID of 0.

From the documentation for BTM_SecClrService:

  Service ID - Id of the service to remove. '0' removes all
               service records (except SDP).

Bug: 65695769, 65223508
Test: BLE connection and characteristic read
Change-Id: Icf309807f02e1faa273cf9bad9c09d9221a8bbfd
Merged-In: Icf309807f02e1faa273cf9bad9c09d9221a8bbfd
(cherry picked from commit 5c5c10683e2a11162838297fc8054b15837c4f32)
(cherry picked from commit 4023c6731d5e991c6202d4e499b9dd43d642fb3c)
(cherry picked from commit f6069908283112f80a57504014fe72e1b5255fa9)
diff --git a/stack/gap/gap_conn.cc b/stack/gap/gap_conn.cc
index 5974aa2..b05a7b2 100644
--- a/stack/gap/gap_conn.cc
+++ b/stack/gap/gap_conn.cc
@@ -176,6 +176,9 @@
   /* update the transport */
   p_ccb->transport = transport;
 
+  /* The service_id must be set before calling gap_release_ccb(). */
+  p_ccb->service_id = service_id;
+
   /* If caller specified a BD address, save it */
   if (p_rem_bda) {
     /* the bd addr is not BT_BD_ANY, then a bd address was specified */
@@ -238,7 +241,6 @@
   }
 
   /* Register with Security Manager for the specific security level */
-  p_ccb->service_id = service_id;
   if (!BTM_SetSecurityLevel((uint8_t)!is_server, p_serv_name, p_ccb->service_id,
                             security, p_ccb->psm, 0, 0)) {
     LOG(ERROR) << "GAP_CONN - Security Error";