• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

hardware/libaudio


Commit MetaInfo

Revision293bd2c92f145997f04048bbc0b15f6b9f742534 (tree)
Time2013-12-09 19:54:34
AuthorMaksim Lin <maks@mani...>
CommiterChih-Wei Huang

Log Message

audio_route: fix mediaserver crash

The segfault is because a null audio_route param is passed into
function reset_mixer_state.

Issue: 1209

Change Summary

Incremental Difference

--- a/audio_route.c
+++ b/audio_route.c
@@ -74,6 +74,11 @@ static void path_free(struct audio_route *ar)
7474 {
7575 unsigned int i;
7676
77+ if (!ar) {
78+ ALOGE("%s: invalid audio_route", __FUNCTION__);
79+ return;
80+ }
81+
7782 for (i = 0; i < ar->num_mixer_paths; i++) {
7883 if (ar->mixer_path[i].name)
7984 free(ar->mixer_path[i].name);
@@ -87,6 +92,10 @@ static struct mixer_path *path_get_by_name(struct audio_route *ar,
8792 const char *name)
8893 {
8994 unsigned int i;
95+ if (!ar) {
96+ ALOGE("%s: invalid audio_route", __FUNCTION__);
97+ return NULL;
98+ }
9099
91100 for (i = 0; i < ar->num_mixer_paths; i++)
92101 if (strcmp(ar->mixer_path[i].name, name) == 0)
@@ -99,6 +108,11 @@ static struct mixer_path *path_create(struct audio_route *ar, const char *name)
99108 {
100109 struct mixer_path *new_mixer_path = NULL;
101110
111+ if (!ar) {
112+ ALOGE("%s: invalid audio_route", __FUNCTION__);
113+ return NULL;
114+ }
115+
102116 if (path_get_by_name(ar, name)) {
103117 ALOGE("Path name '%s' already exists", name);
104118 return NULL;
@@ -205,6 +219,11 @@ static int path_apply(struct audio_route *ar, struct mixer_path *path)
205219 unsigned int i;
206220 unsigned int j;
207221
222+ if (!ar) {
223+ ALOGE("%s: invalid audio_route", __FUNCTION__);
224+ return -1;
225+ }
226+
208227 for (i = 0; i < path->length; i++) {
209228 struct mixer_ctl *ctl = path->setting[i].ctl;
210229
@@ -320,6 +339,11 @@ static int alloc_mixer_state(struct audio_route *ar)
320339 {
321340 unsigned int i;
322341
342+ if (!ar) {
343+ ALOGE("%s: invalid audio_route", __FUNCTION__);
344+ return -1;
345+ }
346+
323347 ar->num_mixer_ctls = mixer_get_num_ctls(ar->mixer);
324348 ar->mixer_state = malloc(ar->num_mixer_ctls * sizeof(struct mixer_state));
325349 if (!ar->mixer_state)
@@ -337,6 +361,10 @@ static int alloc_mixer_state(struct audio_route *ar)
337361
338362 static void free_mixer_state(struct audio_route *ar)
339363 {
364+ if (!ar) {
365+ ALOGE("%s: invalid audio_route", __FUNCTION__);
366+ return;
367+ }
340368 free(ar->mixer_state);
341369 ar->mixer_state = NULL;
342370 }
@@ -346,6 +374,11 @@ void update_mixer_state(struct audio_route *ar)
346374 unsigned int i;
347375 unsigned int j;
348376
377+ if (!ar) {
378+ ALOGE("%s: invalid audio_route", __FUNCTION__);
379+ return;
380+ }
381+
349382 for (i = 0; i < ar->num_mixer_ctls; i++) {
350383 /* if the value has changed, update the mixer */
351384 if (ar->mixer_state[i].old_value != ar->mixer_state[i].new_value) {
@@ -363,6 +396,11 @@ static void save_mixer_state(struct audio_route *ar)
363396 {
364397 unsigned int i;
365398
399+ if (!ar) {
400+ ALOGE("%s: invalid audio_route", __FUNCTION__);
401+ return;
402+ }
403+
366404 for (i = 0; i < ar->num_mixer_ctls; i++) {
367405 /* only get value 0, assume multiple ctl values are the same */
368406 ar->mixer_state[i].reset_value = mixer_ctl_get_value(ar->mixer_state[i].ctl, 0);
@@ -374,6 +412,11 @@ void reset_mixer_state(struct audio_route *ar)
374412 {
375413 unsigned int i;
376414
415+ if (!ar) {
416+ ALOGE("%s: invalid audio_route", __FUNCTION__);
417+ return;
418+ }
419+
377420 /* load all of the saved values */
378421 for (i = 0; i < ar->num_mixer_ctls; i++)
379422 ar->mixer_state[i].new_value = ar->mixer_state[i].reset_value;
@@ -384,7 +427,7 @@ void audio_route_apply_path(struct audio_route *ar, const char *name)
384427 struct mixer_path *path;
385428
386429 if (!ar) {
387- ALOGE("invalid audio_route");
430+ ALOGE("%s: invalid audio_route", __FUNCTION__);
388431 return;
389432 }
390433
@@ -488,6 +531,10 @@ err_calloc:
488531
489532 void audio_route_free(struct audio_route *ar)
490533 {
534+ if (!ar) {
535+ ALOGE("%s: invalid audio_route", __FUNCTION__);
536+ return;
537+ }
491538 free_mixer_state(ar);
492539 mixer_close(ar->mixer);
493540 free(ar);