hal: Fix potential memory leaks in HAL

Fix potential memory leaks in HAL

Change-Id: Ifd491cc185a7d1afa647f03639e57d1685d18803
diff --git a/hal/audio_extn/audio_extn.c b/hal/audio_extn/audio_extn.c
index e65ec76..3482127 100644
--- a/hal/audio_extn/audio_extn.c
+++ b/hal/audio_extn/audio_extn.c
@@ -420,9 +420,28 @@
          */
         query_44_1 = str_parms_create_str(AUDIO_PARAMETER_KEY_NATIVE_AUDIO);
         reply_44_1 = str_parms_create();
+        if (!query_44_1 || !reply_44_1) {
+            if (query_44_1) {
+                str_parms_destroy(query_44_1);
+            }
+            if (reply_44_1) {
+                str_parms_destroy(reply_44_1);
+            }
+
+            ALOGE("%s: param creation failed", __func__);
+            return;
+        }
+
         platform_get_parameters(adev->platform, query_44_1, reply_44_1);
 
         parms_disable_44_1 = str_parms_create();
+        if (!parms_disable_44_1) {
+            str_parms_destroy(query_44_1);
+            str_parms_destroy(reply_44_1);
+            ALOGE("%s: param creation failed for parms_disable_44_1", __func__);
+            return;
+        }
+
         str_parms_add_str(parms_disable_44_1, AUDIO_PARAMETER_KEY_NATIVE_AUDIO, "false");
         platform_set_parameters(adev->platform, parms_disable_44_1);
         str_parms_destroy(parms_disable_44_1);
diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c
index d91763e..45fa223 100644
--- a/hal/audio_extn/utils.c
+++ b/hal/audio_extn/utils.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.
  * Not a Contribution.
  *
  * Copyright (C) 2014 The Android Open Source Project
@@ -375,6 +375,7 @@
     root = config_node("", "");
     if (root == NULL) {
         ALOGE("cfg_list, NULL config root");
+        free(data);
         return;
     }
 
@@ -382,6 +383,9 @@
     load_output(root, platform, streams_output_cfg_list);
 
     send_app_type_cfg(platform, mixer, streams_output_cfg_list);
+
+    config_free(root);
+    free(data);
 }
 
 void audio_extn_utils_dump_streams_output_cfg_list(
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index ae7853e..f8b9652 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -2148,7 +2148,7 @@
 {
     struct stream_out *out = (struct stream_out *)stream;
     struct str_parms *query = str_parms_create_str(keys);
-    char *str;
+    char *str = (char*) NULL;
     char value[256];
     struct str_parms *reply = str_parms_create();
     size_t i, j;
@@ -2156,6 +2156,12 @@
     bool first = true;
 
     if (!query || !reply) {
+        if (reply) {
+            str_parms_destroy(reply);
+        }
+        if (query) {
+            str_parms_destroy(query);
+        }
         ALOGE("out_get_parameters: failed to allocate mem for query or reply");
         return NULL;
     }
@@ -2201,6 +2207,8 @@
             strlcat(value, "false", sizeof(value));
         }
         str_parms_add_str(reply, "is_direct_pcm_track", value);
+        if (str)
+            free(str);
         str = str_parms_to_str(reply);
     }
 
@@ -2223,6 +2231,8 @@
             i++;
         }
         str_parms_add_str(reply, AUDIO_PARAMETER_STREAM_SUP_FORMATS, value);
+        if (str)
+            free(str);
         str = str_parms_to_str(reply);
     }
     str_parms_destroy(query);
@@ -2808,6 +2818,12 @@
     struct str_parms *reply = str_parms_create();
 
     if (!query || !reply) {
+        if (reply) {
+            str_parms_destroy(reply);
+        }
+        if (query) {
+            str_parms_destroy(query);
+        }
         ALOGE("in_get_parameters: failed to create query or reply");
         return NULL;
     }
@@ -3528,6 +3544,12 @@
     int ret = 0;
 
     if (!query || !reply) {
+        if (reply) {
+            str_parms_destroy(reply);
+        }
+        if (query) {
+            str_parms_destroy(query);
+        }
         ALOGE("adev_get_parameters: failed to create query or reply");
         return NULL;
     }