hardware/libaudio
Révision | 293bd2c92f145997f04048bbc0b15f6b9f742534 (tree) |
---|---|
l'heure | 2013-12-09 19:54:34 |
Auteur | Maksim Lin <maks@mani...> |
Commiter | Chih-Wei Huang |
audio_route: fix mediaserver crash
The segfault is because a null audio_route param is passed into
function reset_mixer_state.
Issue: 1209
@@ -74,6 +74,11 @@ static void path_free(struct audio_route *ar) | ||
74 | 74 | { |
75 | 75 | unsigned int i; |
76 | 76 | |
77 | + if (!ar) { | |
78 | + ALOGE("%s: invalid audio_route", __FUNCTION__); | |
79 | + return; | |
80 | + } | |
81 | + | |
77 | 82 | for (i = 0; i < ar->num_mixer_paths; i++) { |
78 | 83 | if (ar->mixer_path[i].name) |
79 | 84 | free(ar->mixer_path[i].name); |
@@ -87,6 +92,10 @@ static struct mixer_path *path_get_by_name(struct audio_route *ar, | ||
87 | 92 | const char *name) |
88 | 93 | { |
89 | 94 | unsigned int i; |
95 | + if (!ar) { | |
96 | + ALOGE("%s: invalid audio_route", __FUNCTION__); | |
97 | + return NULL; | |
98 | + } | |
90 | 99 | |
91 | 100 | for (i = 0; i < ar->num_mixer_paths; i++) |
92 | 101 | 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) | ||
99 | 108 | { |
100 | 109 | struct mixer_path *new_mixer_path = NULL; |
101 | 110 | |
111 | + if (!ar) { | |
112 | + ALOGE("%s: invalid audio_route", __FUNCTION__); | |
113 | + return NULL; | |
114 | + } | |
115 | + | |
102 | 116 | if (path_get_by_name(ar, name)) { |
103 | 117 | ALOGE("Path name '%s' already exists", name); |
104 | 118 | return NULL; |
@@ -205,6 +219,11 @@ static int path_apply(struct audio_route *ar, struct mixer_path *path) | ||
205 | 219 | unsigned int i; |
206 | 220 | unsigned int j; |
207 | 221 | |
222 | + if (!ar) { | |
223 | + ALOGE("%s: invalid audio_route", __FUNCTION__); | |
224 | + return -1; | |
225 | + } | |
226 | + | |
208 | 227 | for (i = 0; i < path->length; i++) { |
209 | 228 | struct mixer_ctl *ctl = path->setting[i].ctl; |
210 | 229 |
@@ -320,6 +339,11 @@ static int alloc_mixer_state(struct audio_route *ar) | ||
320 | 339 | { |
321 | 340 | unsigned int i; |
322 | 341 | |
342 | + if (!ar) { | |
343 | + ALOGE("%s: invalid audio_route", __FUNCTION__); | |
344 | + return -1; | |
345 | + } | |
346 | + | |
323 | 347 | ar->num_mixer_ctls = mixer_get_num_ctls(ar->mixer); |
324 | 348 | ar->mixer_state = malloc(ar->num_mixer_ctls * sizeof(struct mixer_state)); |
325 | 349 | if (!ar->mixer_state) |
@@ -337,6 +361,10 @@ static int alloc_mixer_state(struct audio_route *ar) | ||
337 | 361 | |
338 | 362 | static void free_mixer_state(struct audio_route *ar) |
339 | 363 | { |
364 | + if (!ar) { | |
365 | + ALOGE("%s: invalid audio_route", __FUNCTION__); | |
366 | + return; | |
367 | + } | |
340 | 368 | free(ar->mixer_state); |
341 | 369 | ar->mixer_state = NULL; |
342 | 370 | } |
@@ -346,6 +374,11 @@ void update_mixer_state(struct audio_route *ar) | ||
346 | 374 | unsigned int i; |
347 | 375 | unsigned int j; |
348 | 376 | |
377 | + if (!ar) { | |
378 | + ALOGE("%s: invalid audio_route", __FUNCTION__); | |
379 | + return; | |
380 | + } | |
381 | + | |
349 | 382 | for (i = 0; i < ar->num_mixer_ctls; i++) { |
350 | 383 | /* if the value has changed, update the mixer */ |
351 | 384 | 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) | ||
363 | 396 | { |
364 | 397 | unsigned int i; |
365 | 398 | |
399 | + if (!ar) { | |
400 | + ALOGE("%s: invalid audio_route", __FUNCTION__); | |
401 | + return; | |
402 | + } | |
403 | + | |
366 | 404 | for (i = 0; i < ar->num_mixer_ctls; i++) { |
367 | 405 | /* only get value 0, assume multiple ctl values are the same */ |
368 | 406 | 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) | ||
374 | 412 | { |
375 | 413 | unsigned int i; |
376 | 414 | |
415 | + if (!ar) { | |
416 | + ALOGE("%s: invalid audio_route", __FUNCTION__); | |
417 | + return; | |
418 | + } | |
419 | + | |
377 | 420 | /* load all of the saved values */ |
378 | 421 | for (i = 0; i < ar->num_mixer_ctls; i++) |
379 | 422 | 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) | ||
384 | 427 | struct mixer_path *path; |
385 | 428 | |
386 | 429 | if (!ar) { |
387 | - ALOGE("invalid audio_route"); | |
430 | + ALOGE("%s: invalid audio_route", __FUNCTION__); | |
388 | 431 | return; |
389 | 432 | } |
390 | 433 |
@@ -488,6 +531,10 @@ err_calloc: | ||
488 | 531 | |
489 | 532 | void audio_route_free(struct audio_route *ar) |
490 | 533 | { |
534 | + if (!ar) { | |
535 | + ALOGE("%s: invalid audio_route", __FUNCTION__); | |
536 | + return; | |
537 | + } | |
491 | 538 | free_mixer_state(ar); |
492 | 539 | mixer_close(ar->mixer); |
493 | 540 | free(ar); |