wlan: Fix memory leak and NULL pointer dereference issues

Few functions doesn't free the allocated memory during failure cases
and dereference the pointer before NULL check.

This includes fix to free the allocated memory during failure cases,
add NULL check before deferencing the pointer and
memory layering violation in SME.

Change-Id: Ia4717c29788612a9b0c6e0286e6d70cefcc81df7
CRs-Fixed: 996173
diff --git a/CORE/HDD/src/wlan_hdd_trace.c b/CORE/HDD/src/wlan_hdd_trace.c
index 2c82982..6901109 100644
--- a/CORE/HDD/src/wlan_hdd_trace.c
+++ b/CORE/HDD/src/wlan_hdd_trace.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2015 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2014-2016 The Linux Foundation. All rights reserved.
  *
  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  *
@@ -151,14 +151,16 @@
     /* get the global voss context */
     vos_ctx_ptr = vos_get_global_context(VOS_MODULE_ID_VOSS, NULL);
 
-    if (NULL != vos_ctx_ptr) {
-        hdd_ctx_ptr = vos_get_context(VOS_MODULE_ID_HDD, vos_ctx_ptr);
-    } else {
-        VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
-                  "%s: Invalid Global VOSS Context", __func__);
+    if (!vos_ctx_ptr) {
+        hddLog(LOGE, FL("Invalid Global VOSS Context"));
         VOS_ASSERT(0);
         return;
     }
+    hdd_ctx_ptr = vos_get_context(VOS_MODULE_ID_HDD, vos_ctx_ptr);
+    if (!hdd_ctx_ptr) {
+       hddLog(LOGE, FL("HDD context is Null"));
+       return;
+    }
 
     hddLog(LOG1,
            FL("mScanPending %d isWlanSuspended %d disable_dfs_flag %d"),