SDP: Allocate proper sized scratch buffer for SDP response

The buffer allocated for attribute response is being reused
for subsequent requests for an SDP connection. Check the
buffer size before using for subsequent requests and
reallocate if required.

Change-Id: Ib00aff2c4512192c29265cf0adb89e380adf0b35
diff --git a/stack/sdp/sdp_server.c b/stack/sdp/sdp_server.c
index 5d11cb4..84dd957 100644
--- a/stack/sdp/sdp_server.c
+++ b/stack/sdp/sdp_server.c
@@ -380,8 +380,14 @@
     else
     {
         /* Get a scratch buffer to store response */
-        if (!p_ccb->rsp_list)
+        if (!p_ccb->rsp_list || (GKI_get_buf_size(p_ccb->rsp_list) < max_list_len))
         {
+            /* Free and reallocate if the earlier allocated buffer is small */
+            if (p_ccb->rsp_list)
+            {
+                GKI_freebuf (p_ccb->rsp_list);
+            }
+
             p_ccb->rsp_list = (UINT8 *)GKI_getbuf (max_list_len);
             if (p_ccb->rsp_list == NULL)
             {
@@ -624,8 +630,14 @@
     else
     {
         /* Get a scratch buffer to store response */
-        if (!p_ccb->rsp_list)
+        if (!p_ccb->rsp_list || (GKI_get_buf_size(p_ccb->rsp_list) < max_list_len))
         {
+            /* Free and reallocate if the earlier allocated buffer is small */
+            if (p_ccb->rsp_list)
+            {
+                GKI_freebuf (p_ccb->rsp_list);
+            }
+
             p_ccb->rsp_list = (UINT8 *)GKI_getbuf (max_list_len);
             if (p_ccb->rsp_list == NULL)
             {