primary-hal: Fix issues found in static analysis

Fix statibility issues found out by static analysis tools

Change-Id: I832ae07c7e722e62059ae855fd7d591343ab74b2
diff --git a/hal/audio_extn/sndmonitor.c b/hal/audio_extn/sndmonitor.c
index 5e39d37..e86d6b6 100644
--- a/hal/audio_extn/sndmonitor.c
+++ b/hal/audio_extn/sndmonitor.c
@@ -81,6 +81,8 @@
 #define AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE "ext_audio_device"
 #define INIT_MAP_SIZE 5
 
+#define FD_INVALID -1
+
 typedef enum {
     audio_event_on,
     audio_event_off
@@ -245,8 +247,11 @@
         }
 
         ret = add_new_sndcard(atoi(ptr), fd);
+
+        close(fd);
+        fd = FD_INVALID;
+
         if (ret != 0) {
-            close(fd);
             continue;
         }
 
@@ -275,8 +280,11 @@
             continue;
 
         ret = add_new_sndcard(CPE_MAGIC_NUM+num_cpe, fd);
+
+        close(fd);
+        fd = FD_INVALID;
+
         if (ret != 0) {
-            close(fd);
             continue;
         }
 
@@ -304,10 +312,11 @@
         }
         if (fd >= 0) {
             ret = add_new_sndcard(SLPI_MAGIC_NUM, fd);
-            if (ret != 0)
-                close(fd);
-            else
+            if (ret == 0)
                 num_cards++;
+
+            close(fd);
+            fd = FD_INVALID;
         }
     }
 
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index b9ac139..0dc1d47 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -5766,16 +5766,28 @@
         ret = platform_get_soft_step_volume_params(volume_params,out->usecase);
         if (ret < 0) {
             ALOGE("%s : platform_get_soft_step_volume_params is fialed", __func__);
-            return -EINVAL;
+            ret = -EINVAL;
+            goto ERR_EXIT;
         }
 
     }
     ret = mixer_ctl_set_array(ctl, volume_params, sizeof(struct soft_step_volume_params)/sizeof(int));
     if (ret < 0) {
         ALOGE("%s: Could not set ctl, error:%d ", __func__, ret);
-        return -EINVAL;
+        ret = -EINVAL;
+        goto ERR_EXIT;
+    }
+
+    if (volume_params) {
+        free(volume_params);
     }
     return 0;
+
+ERR_EXIT:
+    if (volume_params) {
+        free(volume_params);
+    }
+    return ret;
 }
 #endif