From 144571da9b5b595d7bb49822e78887771554b68b Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 28 Sep 2015 17:21:49 +0200 Subject: ao_coreaudio_utils: fix error handling in device listing code This could sometimes cause crashes in hotplug events. (Apparently in cases when CoreAudio changes its state asynchronously, or such.) CA_GET_STR() does not set the string if there was an error, so errors have to be strictly checked before using it. --- audio/out/ao_coreaudio_utils.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'audio/out/ao_coreaudio_utils.c') diff --git a/audio/out/ao_coreaudio_utils.c b/audio/out/ao_coreaudio_utils.c index f6463a314a..7d14b3f75c 100644 --- a/audio/out/ao_coreaudio_utils.c +++ b/audio/out/ao_coreaudio_utils.c @@ -51,7 +51,9 @@ static bool ca_is_output_device(struct ao *ao, AudioDeviceID dev) size_t n_buffers; AudioBufferList *buffers; const ca_scope scope = kAudioDevicePropertyStreamConfiguration; - CA_GET_ARY_O(dev, scope, &buffers, &n_buffers); + OSStatus err = CA_GET_ARY_O(dev, scope, &buffers, &n_buffers); + if (err != noErr) + return false; talloc_free(buffers); return n_buffers > 0; } @@ -71,11 +73,16 @@ void ca_get_device_list(struct ao *ao, struct ao_device_list *list) char *name; char *desc; err = CA_GET_STR(devs[i], kAudioDevicePropertyDeviceUID, &name); + if (err != noErr) { + MP_VERBOSE(ao, "skipping device %d, which has no UID\n", i); + talloc_free(ta_ctx); + continue; + } talloc_steal(ta_ctx, name); err = CA_GET_STR(devs[i], kAudioObjectPropertyName, &desc); - talloc_steal(ta_ctx, desc); if (err != noErr) - desc = "Unknown"; + desc = talloc_strdup(NULL, "Unknown"); + talloc_steal(ta_ctx, desc); ao_device_list_add(list, ao, &(struct ao_device_desc){name, desc}); talloc_free(ta_ctx); } -- cgit v1.2.3