bta_gattc: Fix initialization and free p_q_cmd

This will prevent crash when ACL is disconnected while GATT search

Bug: 253200147
Test: atest BluetoothInstrumentationTests
Test: manual disconnect while bonding and discovering
Tag: #feature
Change-Id: If7ad51378b650b67e551f8bbec7b38d0d9c14cbd
diff --git a/system/bta/gatt/bta_gattc_utils.cc b/system/bta/gatt/bta_gattc_utils.cc
index 1412702..6c483c1 100644
--- a/system/bta/gatt/bta_gattc_utils.cc
+++ b/system/bta/gatt/bta_gattc_utils.cc
@@ -146,6 +146,7 @@
       p_clcb->status = GATT_SUCCESS;
       p_clcb->transport = transport;
       p_clcb->bda = remote_bda;
+      p_clcb->p_q_cmd = NULL;
 
       p_clcb->p_rcb = bta_gattc_cl_get_regcb(client_if);
 
@@ -217,7 +218,9 @@
     p_srcb->gatt_database.Clear();
   }
 
-  osi_free_and_reset((void**)&p_clcb->p_q_cmd);
+  if (p_clcb->p_q_cmd != NULL) {
+    osi_free_and_reset((void**)&p_clcb->p_q_cmd);
+  }
   memset(p_clcb, 0, sizeof(tBTA_GATTC_CLCB));
 }