From c2c00ce6c2e22bf4bb0dad17952dd3af2c447d6a Mon Sep 17 00:00:00 2001 From: Tanu Kaskinen Date: Wed, 3 Jul 2013 14:09:09 +0300 Subject: [PATCH] alsa: Handle pa_device_port_new() failures pa_device_port_new() can't currently fail, but it soon can. --- src/modules/alsa/alsa-mixer.c | 21 ++++++++++++++++++--- src/modules/alsa/alsa-ucm.c | 17 +++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c index 71dfa7975..f77667f51 100644 --- a/src/modules/alsa/alsa-mixer.c +++ b/src/modules/alsa/alsa-mixer.c @@ -4500,7 +4500,12 @@ static pa_device_port* device_port_alsa_init(pa_hashmap *ports, /* card ports */ p = pa_device_port_new(core, &port_data, sizeof(pa_alsa_port_data)); pa_device_port_new_data_done(&port_data); - pa_assert(p); + + if (!p) { + pa_log("Failed to create port %s.", name); + goto fail; + } + pa_hashmap_put(ports, p->name, p); pa_proplist_update(p->proplist, PA_UPDATE_REPLACE, path->proplist); @@ -4519,6 +4524,9 @@ static pa_device_port* device_port_alsa_init(pa_hashmap *ports, /* card ports */ } return p; + +fail: + return NULL; } void pa_alsa_path_set_add_ports( @@ -4542,6 +4550,10 @@ void pa_alsa_path_set_add_ports( * single entry */ pa_device_port *port = device_port_alsa_init(ports, path->name, path->description, path, path->settings, cp, extra, core); + + if (!port) + continue; + port->priority = path->priority * 100; } else { @@ -4558,10 +4570,13 @@ void pa_alsa_path_set_add_ports( d = pa_xstrdup(path->description); port = device_port_alsa_init(ports, n, d, path, s, cp, extra, core); - port->priority = path->priority * 100 + s->priority; - pa_xfree(n); pa_xfree(d); + + if (!port) + continue; + + port->priority = path->priority * 100 + s->priority; } } } diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c index 9eb6412b5..fc862996d 100644 --- a/src/modules/alsa/alsa-ucm.c +++ b/src/modules/alsa/alsa-ucm.c @@ -678,7 +678,8 @@ static void ucm_add_port_combination( int i; unsigned priority; double prio2; - char *name, *desc; + char *name = NULL; + char *desc = NULL; const char *dev_name; const char *direction; pa_alsa_ucm_device *dev; @@ -731,7 +732,11 @@ static void ucm_add_port_combination( port = pa_device_port_new(core, &port_data, 0); pa_device_port_new_data_done(&port_data); - pa_assert(port); + + if (!port) { + pa_log("Failed to create port %s.", name); + goto fail; + } pa_hashmap_put(ports, port->name, port); pa_log_debug("Add port %s: %s", port->name, port->description); @@ -741,7 +746,9 @@ static void ucm_add_port_combination( port->priority = priority; pa_xfree(name); + name = NULL; pa_xfree(desc); + desc = NULL; direction = is_sink ? "output" : "input"; pa_log_debug("Port %s direction %s, priority %d", port->name, direction, priority); @@ -755,6 +762,12 @@ static void ucm_add_port_combination( pa_hashmap_put(hash, port->name, port); pa_device_port_ref(port); } + + return; + +fail: + pa_xfree(name); + pa_xfree(desc); } static int ucm_port_contains(const char *port_name, const char *dev_name, bool is_sink) {