Wifi-HAL: Move llstats freeing to a common API

Link layer stats are getting freed at multiple places. Better
to have a common API and call it.

Change-Id: I06aa330fc955d7266c9e83e4d7abca6098338cd5
diff --git a/qcwcn/wifi_hal/llstats.cpp b/qcwcn/wifi_hal/llstats.cpp
index eeabc06..c4db2ab 100644
--- a/qcwcn/wifi_hal/llstats.cpp
+++ b/qcwcn/wifi_hal/llstats.cpp
@@ -871,6 +871,14 @@
         ret = WIFI_ERROR_INVALID_ARGS;
     }
 
+    clearStats();
+
+    return ret;
+}
+
+
+void LLStatsCommand::clearStats()
+{
     if(mResultsParams.radio_stat)
     {
         if (mResultsParams.radio_stat->tx_time_per_levels)
@@ -888,8 +896,6 @@
         free(mResultsParams.iface_stat);
         mResultsParams.iface_stat = NULL;
      }
-
-     return ret;
 }
 
 
@@ -1233,24 +1239,7 @@
     return NL_SKIP;
 
 cleanup:
-    if(mResultsParams.radio_stat)
-    {
-        if (mResultsParams.radio_stat->tx_time_per_levels)
-        {
-            free(mResultsParams.radio_stat->tx_time_per_levels);
-            mResultsParams.radio_stat->tx_time_per_levels = NULL;
-        }
-        free(mResultsParams.radio_stat);
-        mResultsParams.radio_stat = NULL;
-        mRadioStatsSize = 0;
-        mNumRadios = 0;
-    }
-
-    if(mResultsParams.iface_stat)
-    {
-        free(mResultsParams.iface_stat);
-        mResultsParams.iface_stat = NULL;
-    }
+    clearStats();
     return status;
 }
 
diff --git a/qcwcn/wifi_hal/llstatscommand.h b/qcwcn/wifi_hal/llstatscommand.h
index 9edf3a7..aef0017 100644
--- a/qcwcn/wifi_hal/llstatscommand.h
+++ b/qcwcn/wifi_hal/llstatscommand.h
@@ -112,6 +112,8 @@
                                             struct nlattr **tb_vendor);
 
     virtual void setHandler(wifi_stats_result_handler handler);
+
+    virtual void clearStats();
 };
 
 #ifdef __cplusplus