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/MAC/src/pe/lim/limApi.c b/CORE/MAC/src/pe/lim/limApi.c
index 84bbedc..6d34461 100644
--- a/CORE/MAC/src/pe/lim/limApi.c
+++ b/CORE/MAC/src/pe/lim/limApi.c
@@ -2232,6 +2232,13 @@
     }
     pSmeLostLinkParams =
     (tpSirSmeLostLinkParamsInd)vos_mem_malloc(sizeof(tSirSmeLostLinkParamsInd));
+    if (NULL == pSmeLostLinkParams)
+    {
+        limLog(pMac, LOGP,
+            FL("Failed to alloc mem of size %zu for tSirSmeLostLinkParamsInd"),
+            sizeof(*pSmeLostLinkParams));
+        return;
+    }
     vos_mem_set(pSmeLostLinkParams, sizeof(tSirSmeLostLinkParamsInd), 0);
     pSmeLostLinkParams->messageType = eWNI_SME_LOST_LINK_PARAMS_IND;
     pSmeLostLinkParams->length = sizeof(tSirSmeLostLinkParamsInd);