module-policy/stream-manager: Fix svace issues 60/53760/4 accepted/tizen/mobile/20151209.132843 accepted/tizen/tv/20151209.132913 accepted/tizen/wearable/20151209.132937 submit/tizen/20151209.082902
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 9 Dec 2015 07:03:33 +0000 (16:03 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 9 Dec 2015 07:18:39 +0000 (16:18 +0900)
[Version] 5.0.23
[Profile] Common
[Issue Type] Static Analysis

Change-Id: Ia1028ab8545d34efffad377f42470c9361dfbb13
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/pulseaudio-modules-tizen.spec
src/module-policy.c
src/stream-manager.c

index 4e68352..9638f74 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          5.0.22
+Version:          5.0.23
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 454cae4..7008639 100644 (file)
@@ -735,7 +735,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_
                         pa_log_debug("[ROUTE][AUTO_ALL] combine_sink_arg1[%s], combine_sink_arg2[%p]", sink->name, combine_sink_arg2);
                     } else if (data->stream_type == STREAM_SINK_INPUT && !combine_sink_arg2) {
                         sink = combine_sink_arg2 = pa_device_manager_get_sink(device, DEVICE_ROLE_NORMAL);
-                        if(sink && !pa_streq(sink->name, combine_sink_arg1->name)) {
+                        if (sink && !pa_streq(sink->name, combine_sink_arg1->name)) {
                             pa_log_debug("[ROUTE][AUTO_ALL] combine_sink_arg2[%s]", sink->name);
                             /* load combine sink */
                             if (!u->module_combine_sink) {
@@ -744,13 +744,16 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_
                                 u->module_combine_sink = pa_module_load(u->core, MODULE_COMBINE_SINK, args);
                                 pa_xfree(args);
                             }
-                            sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK);
-                            PA_IDXSET_FOREACH (s, combine_sink_arg1->inputs, s_idx) {
-                                if (s == data->stream) {
-                                    pa_sink_input_move_to(s, sink, FALSE);
-                                    pa_log_debug("[ROUTE][AUTO_ALL] *** sink-#if 0input(%p,%u) moves to sink(%p,%s)", s, ((pa_sink_input*)s)->index, sink, sink->name);
+                            if ((sink = (pa_sink*)pa_namereg_get(u->core, SINK_NAME_COMBINED, PA_NAMEREG_SINK))) {
+                                PA_IDXSET_FOREACH (s, combine_sink_arg1->inputs, s_idx) {
+                                    if (s == data->stream) {
+                                        pa_sink_input_move_to(s, sink, FALSE);
+                                        pa_log_debug("[ROUTE][AUTO_ALL] *** sink-nput(%p,%u) moves to sink(%p,%s)",
+                                                     s, ((pa_sink_input*)s)->index, sink, sink->name);
+                                    }
                                 }
-                            }
+                            } else
+                                pa_log_error("[ROUTE][AUTO_ALL] could not get combine_sink");
                         }
                     } else if (data->stream_type == STREAM_SOURCE_OUTPUT)
                         source = pa_device_manager_get_source(device, DEVICE_ROLE_NORMAL);
@@ -764,17 +767,16 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_
                         /* move sink-inputs/source-outputs if needed */
                         if (data->idx_streams) {
                             PA_IDXSET_FOREACH (s, data->idx_streams, s_idx) { /* data->idx_streams: null_sink */
-                                if ((sink && (sink != ((pa_sink_input*)s)->sink)) || (source && (source != ((pa_source_output*)s)->source))) {
-                                    if (!pa_stream_manager_get_route_type(s, FALSE, data->stream_type, &route_type) && (route_type == STREAM_ROUTE_TYPE_AUTO_ALL)) {
-                                        if (data->stream_type == STREAM_SINK_INPUT) {
-                                            pa_sink_input_move_to(s, sink, FALSE);
-                                            pa_log_debug("[ROUTE][AUTO_ALL] *** sink-input(%p,%u) moves to sink(%p,%s)",
-                                                         s, ((pa_sink_input*)s)->index, sink, sink->name);
-                                        } else if (data->stream_type == STREAM_SOURCE_OUTPUT) {
-                                            pa_source_output_move_to(s, source, FALSE);
-                                            pa_log_debug("[ROUTE][AUTO_ALL] *** source-output(%p,%u) moves to source(%p,%s)",
-                                                         s, ((pa_source_output*)s)->index, source, source->name);
-                                        }
+                                if (!pa_stream_manager_get_route_type(s, FALSE, data->stream_type, &route_type) &&
+                                    (route_type == STREAM_ROUTE_TYPE_AUTO_ALL)) {
+                                    if ((data->stream_type == STREAM_SINK_INPUT) && (sink && (sink != ((pa_sink_input*)s)->sink))) {
+                                        pa_sink_input_move_to(s, sink, FALSE);
+                                        pa_log_debug("[ROUTE][AUTO_ALL] *** sink-input(%p,%u) moves to sink(%p,%s)",
+                                                     s, ((pa_sink_input*)s)->index, sink, sink->name);
+                                    } else if ((data->stream_type == STREAM_SOURCE_OUTPUT) && (source && (source != ((pa_source_output*)s)->source))) {
+                                        pa_source_output_move_to(s, source, FALSE);
+                                        pa_log_debug("[ROUTE][AUTO_ALL] *** source-output(%p,%u) moves to source(%p,%s)",
+                                                     s, ((pa_source_output*)s)->index, source, source->name);
                                     }
                                 }
                             }
@@ -1619,9 +1621,6 @@ int pa__init(pa_module *m)
     return 0;
 
 fail:
-    if (ma)
-        pa_modargs_free(ma);
-
     pa__done(m);
 
     return -1;
index 808ca6c..dd20e7e 100644 (file)
@@ -1073,22 +1073,24 @@ static void handle_update_focus_status(DBusConnection *conn, DBusMessage *msg, v
         if (sp->focus_status != (acquired_focus_status & (STREAM_FOCUS_ACQUIRED_PLAYBACK|STREAM_FOCUS_ACQUIRED_CAPTURE))) {
             /* need to update */
             sp->focus_status = acquired_focus_status & (STREAM_FOCUS_ACQUIRED_PLAYBACK|STREAM_FOCUS_ACQUIRED_CAPTURE);
-            if (sp->idx_sink_inputs)
+            if (sp->idx_sink_inputs) {
                 count = pa_idxset_size(sp->idx_sink_inputs);
-               PA_IDXSET_FOREACH(stream, sp->idx_sink_inputs, idx) {
-                   pa_proplist_sets(GET_STREAM_PROPLIST(stream, STREAM_SINK_INPUT), PA_PROP_MEDIA_FOCUS_STATUS,
-                        IS_FOCUS_ACQUIRED(sp->focus_status, STREAM_SINK_INPUT)?STREAM_FOCUS_PLAYBACK:STREAM_FOCUS_NONE);
+                PA_IDXSET_FOREACH(stream, sp->idx_sink_inputs, idx) {
+                    pa_proplist_sets(GET_STREAM_PROPLIST(stream, STREAM_SINK_INPUT), PA_PROP_MEDIA_FOCUS_STATUS,
+                                     IS_FOCUS_ACQUIRED(sp->focus_status, STREAM_SINK_INPUT)?STREAM_FOCUS_PLAYBACK:STREAM_FOCUS_NONE);
                     if (--count == 0)
                         process_stream(m, stream, STREAM_SINK_INPUT, PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_FOCUS_CHANGED, FALSE);
                 }
-            if (sp->idx_source_outputs)
+            }
+            if (sp->idx_source_outputs) {
                 count = pa_idxset_size(sp->idx_source_outputs);
                 PA_IDXSET_FOREACH(stream, sp->idx_source_outputs, idx) {
                     pa_proplist_sets(GET_STREAM_PROPLIST(stream, STREAM_SOURCE_OUTPUT), PA_PROP_MEDIA_FOCUS_STATUS,
-                        IS_FOCUS_ACQUIRED(sp->focus_status, STREAM_SOURCE_OUTPUT)?STREAM_FOCUS_CAPTURE:STREAM_FOCUS_NONE);
+                                     IS_FOCUS_ACQUIRED(sp->focus_status, STREAM_SOURCE_OUTPUT)?STREAM_FOCUS_CAPTURE:STREAM_FOCUS_NONE);
                     if (--count == 0)
                         process_stream(m, stream, STREAM_SOURCE_OUTPUT, PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_FOCUS_CHANGED, FALSE);
                 }
+            }
         } else
             pa_log_debug("same as before, skip updating focus status[0x%x]", acquired_focus_status);
 
@@ -1826,66 +1828,73 @@ static void fill_device_info_to_hook_data(pa_stream_manager *m, void *hook_data,
     switch (command) {
     case NOTIFY_COMMAND_SELECT_PROPER_SINK_OR_SOURCE_FOR_INIT: {
         select_data = (pa_stream_manager_hook_data_for_select*)hook_data;
-        si = pa_hashmap_get(m->stream_infos, select_data->stream_role);
-        select_data->route_type = si->route_type;
-        avail_devices = (type == STREAM_SINK_INPUT) ? si->idx_avail_out_devices : si->idx_avail_in_devices;
-        list_len = pa_idxset_size(avail_devices);
-        device_none = pa_idxset_get_by_data(avail_devices, "none", NULL);
-        if (list_len == 0 || device_none) {
-            pa_log_warn("  -- there is no available device, stream_type(%d)", type);
-            break;
-        }
-        select_data->idx_avail_devices = avail_devices;
-        select_data->origins_from_new_data = is_new_data;
-        if (si->route_type >= STREAM_ROUTE_TYPE_MANUAL) {
+        if ((si = pa_hashmap_get(m->stream_infos, select_data->stream_role))) {
+            select_data->route_type = si->route_type;
+            avail_devices = (type == STREAM_SINK_INPUT) ? si->idx_avail_out_devices : si->idx_avail_in_devices;
+            list_len = pa_idxset_size(avail_devices);
+            device_none = pa_idxset_get_by_data(avail_devices, "none", NULL);
+
+            if (list_len == 0 || device_none) {
+                pa_log_warn("  -- there is no available device, stream_type(%d)", type);
+                break;
+            }
+            select_data->idx_avail_devices = avail_devices;
+            select_data->origins_from_new_data = is_new_data;
+            if (si->route_type >= STREAM_ROUTE_TYPE_MANUAL) {
+                if (is_new_data)
+                    p_idx = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_PARENT_ID);
+                else
+                    p_idx = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_PARENT_ID);
+                if (p_idx && !pa_atou(p_idx, &parent_idx)) {
+                    /* find parent idx, it's device info. and it's stream idxs */
+                    sp = pa_hashmap_get(m->stream_parents, (const void*)parent_idx);
+                    if (sp)
+                        select_data->idx_manual_devices = (type == STREAM_SINK_INPUT) ? (sp->idx_route_out_devices) : (sp->idx_route_in_devices);
+                    else
+                        pa_log_warn("  -- failed to get the stream parent of idx(%u)", parent_idx);
+                } else
+                    pa_log_warn("  -- could not get the parent id of this stream, but keep going...");
+            }
+        } else
+            pa_log_error("  -- could not find (%s)", route_data->stream_role);
+
+        break;
+    }
+    case NOTIFY_COMMAND_CHANGE_ROUTE_START:
+    case NOTIFY_COMMAND_CHANGE_ROUTE_END: {
+        route_data = (pa_stream_manager_hook_data_for_route*)hook_data;
+        if ((si = pa_hashmap_get(m->stream_infos, route_data->stream_role))) {
+            avail_devices = (type == STREAM_SINK_INPUT) ? si->idx_avail_out_devices : si->idx_avail_in_devices;
+            route_data->route_type = si->route_type;
+            list_len = pa_idxset_size(avail_devices);
+            device_none = pa_idxset_get_by_data(avail_devices, "none", NULL);
+
+            if (list_len == 0 || device_none) {
+                pa_log_warn("  -- there is no available device, stream_type(%d)", type);
+                break;
+            }
             if (is_new_data)
                 p_idx = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_PARENT_ID);
             else
                 p_idx = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_PARENT_ID);
             if (p_idx && !pa_atou(p_idx, &parent_idx)) {
-                /* find parent idx, it's device info. and it's stream idxs */
                 sp = pa_hashmap_get(m->stream_parents, (const void*)parent_idx);
-                if (sp)
-                    select_data->idx_manual_devices = (type == STREAM_SINK_INPUT) ? (sp->idx_route_out_devices) : (sp->idx_route_in_devices);
-                else
+                if (!sp)
                     pa_log_warn("  -- failed to get the stream parent of idx(%u)", parent_idx);
             } else
-                pa_log_warn("  -- could not get the parent id of this stream, but keep going...");
-        }
-        break;
-    }
-    case NOTIFY_COMMAND_CHANGE_ROUTE_START:
-    case NOTIFY_COMMAND_CHANGE_ROUTE_END: {
-        route_data = (pa_stream_manager_hook_data_for_route*)hook_data;
-        si = pa_hashmap_get(m->stream_infos, route_data->stream_role);
-        avail_devices = (type == STREAM_SINK_INPUT) ? si->idx_avail_out_devices : si->idx_avail_in_devices;
-        route_data->route_type = si->route_type;
-        list_len = pa_idxset_size(avail_devices);
-        device_none = pa_idxset_get_by_data(avail_devices, "none", NULL);
-
-        if (is_new_data)
-            p_idx = pa_proplist_gets(GET_STREAM_NEW_PROPLIST(stream, type), PA_PROP_MEDIA_PARENT_ID);
-        else
-            p_idx = pa_proplist_gets(GET_STREAM_PROPLIST(stream, type), PA_PROP_MEDIA_PARENT_ID);
-        if (p_idx && !pa_atou(p_idx, &parent_idx)) {
-            sp = pa_hashmap_get(m->stream_parents, (const void*)parent_idx);
-            if (!sp)
-                pa_log_warn("  -- failed to get the stream parent of idx(%u)", parent_idx);
+               pa_log_warn("  -- could not get the parent id of this stream, but keep going...");
+
+            route_data->idx_avail_devices = avail_devices;
+            if (si->route_type >= STREAM_ROUTE_TYPE_MANUAL) {
+                if (sp) {
+                    route_data->idx_manual_devices = (type == STREAM_SINK_INPUT) ? (sp->idx_route_out_devices) : (sp->idx_route_in_devices);
+                    route_data->idx_streams = (type == STREAM_SINK_INPUT) ? (sp->idx_sink_inputs) : (sp->idx_source_outputs);
+                } else
+                    pa_log_warn("  -- failed to get the stream parent of idx(%u)", parent_idx);
+            }
         } else
-           pa_log_warn("  -- could not get the parent id of this stream, but keep going...");
+            pa_log_error("  -- could not find (%s)", route_data->stream_role);
 
-        if (list_len == 0 || device_none) {
-            pa_log_warn("  -- there is no available device, stream_type(%d)", type);
-            break;
-        }
-        route_data->idx_avail_devices = avail_devices;
-        if (si->route_type >= STREAM_ROUTE_TYPE_MANUAL) {
-            if (sp) {
-                route_data->idx_manual_devices = (type == STREAM_SINK_INPUT) ? (sp->idx_route_out_devices) : (sp->idx_route_in_devices);
-                route_data->idx_streams = (type == STREAM_SINK_INPUT) ? (sp->idx_sink_inputs) : (sp->idx_source_outputs);
-            } else
-                pa_log_warn("  -- failed to get the stream parent of idx(%u)", parent_idx);
-        }
         break;
     }
     default:
@@ -2975,7 +2984,7 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_device_
                             ((route_type == STREAM_ROUTE_TYPE_AUTO) || (route_type == STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED))) {
                             /* remove activated device info. if it has the AUTO route type */
                             active_dev = pa_proplist_gets(GET_STREAM_PROPLIST(s, STREAM_SOURCE_OUTPUT), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV);
-                            if (pa_streq(active_dev, device_type))
+                            if (active_dev && pa_streq(active_dev, device_type))
                                 pa_proplist_sets(GET_STREAM_PROPLIST(s, STREAM_SOURCE_OUTPUT), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, ACTIVE_DEV_REMOVED);
                         }
                     }
@@ -2999,7 +3008,7 @@ static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_device_
                             ((route_type == STREAM_ROUTE_TYPE_AUTO) || (route_type == STREAM_ROUTE_TYPE_AUTO_LAST_CONNECTED))) {
                             /* remove activated device info. if it has the AUTO route type */
                             active_dev = pa_proplist_gets(GET_STREAM_PROPLIST(s, STREAM_SINK_INPUT), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV);
-                            if (pa_streq(active_dev, device_type))
+                            if (active_dev && pa_streq(active_dev, device_type))
                                 pa_proplist_sets(GET_STREAM_PROPLIST(s, STREAM_SINK_INPUT), PA_PROP_MEDIA_ROUTE_AUTO_ACTIVE_DEV, ACTIVE_DEV_REMOVED);
                         }
                     }
@@ -3036,7 +3045,7 @@ static void subscribe_cb(pa_core *core, pa_subscription_event_type_t t, uint32_t
         return;
     }
     name = pa_proplist_gets(client->proplist, PA_PROP_APPLICATION_NAME);
-    if (strncmp (name, STREAM_MANAGER_CLIENT_NAME, strlen(STREAM_MANAGER_CLIENT_NAME))) {
+    if (name && strncmp (name, STREAM_MANAGER_CLIENT_NAME, strlen(STREAM_MANAGER_CLIENT_NAME))) {
         pa_log_warn(" - this is not a client(%s) that we should take care of, skip it", name);
         return;
     }