hal: effects: volume_listner: check for invalid handle in release

- check for NULL handle
- break from loop once handle is found

Change-Id: I460cb3105383f05618cd5a953bf24b87ad2ff30c
diff --git a/post_proc/volume_listener.c b/post_proc/volume_listener.c
index 51f8803..a72c1e9 100644
--- a/post_proc/volume_listener.c
+++ b/post_proc/volume_listener.c
@@ -681,6 +681,11 @@
     bool recompute_flag = false;
     int active_stream_count = 0;
     ALOGV("%s context %p", __func__, handle);
+    if (recv_contex == NULL || recv_contex->desc == NULL) {
+        ALOGE("%s: Got invalid handle while release, DO NOTHING ", __func__);
+        return status;
+    }
+
     pthread_mutex_lock(&vol_listner_init_lock);
 
     // check if the handle/context provided is valid
@@ -690,13 +695,14 @@
             && (context->session_id == recv_contex->session_id)
             && (context->stream_type == recv_contex->stream_type)) {
             ALOGV("--- Found something to remove ---");
-            list_remove(&context->effect_list_node);
             PRINT_STREAM_TYPE(context->stream_type);
             if (context->dev_id && AUDIO_DEVICE_OUT_SPEAKER) {
                 recompute_flag = true;
             }
+            list_remove(&context->effect_list_node);
             free(context);
             status = 0;
+            break;
         } else {
             ++active_stream_count;
         }