Promotion of fm.lnx.2.1-00007.

CRs      Change ID                                   Subject
--------------------------------------------------------------------------------------------------------------
1072045   Ibb2cf98ade08bbc9b25946d2368b1b7e428397bc   fm: synchronize dequeue_fm_tx_cmd function

Change-Id: I7d1beecd162066ed833823e1226ae803300a1443
CRs-Fixed: 1072045
diff --git a/fm_hci/fm_hci.c b/fm_hci/fm_hci.c
index 8c6173a..2fafe83 100644
--- a/fm_hci/fm_hci.c
+++ b/fm_hci/fm_hci.c
@@ -138,12 +138,11 @@
         }
         pthread_mutex_unlock(&hci->tx_q_lock);
 
-wait_for_cmd_credits:
         pthread_mutex_lock(&hci->credit_lock);
+wait_for_cmd_credits:
         while (hci->command_credits == 0) {
               pthread_cond_wait(&hci->cmd_credits_cond, &hci->credit_lock);
         }
-        pthread_mutex_unlock(&hci->credit_lock);
 
         /* Check if we really got the command credits */
         if (hci->command_credits) {
@@ -160,14 +159,18 @@
             count = 0;
 
             /* Decrement cmd credits by '1' after sending the cmd*/
-            pthread_mutex_lock(&hci->credit_lock);
             hci->command_credits--;
-            pthread_mutex_unlock(&hci->credit_lock);
+            if (temp->hdr)
+                free(temp->hdr);
+            free(temp);
         } else {
-            if (!lib_running)
+            if (!lib_running) {
+                pthread_mutex_unlock(&hci->credit_lock);
                 break;
+            }
             goto wait_for_cmd_credits;
         }
+        pthread_mutex_unlock(&hci->credit_lock);
     }
 }