[pulseaudio-discuss] [PATCH v2 06/18] alsa: Handle pa_device_port_new() failures

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Fri Jun 28 00:48:00 PDT 2013


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 b2f6c2e..63afc24 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -4499,7 +4499,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);
 
@@ -4518,6 +4523,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(
@@ -4540,6 +4548,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 {
@@ -4556,10 +4568,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 bc2ea9b..1c1cd9c 100644
--- a/src/modules/alsa/alsa-ucm.c
+++ b/src/modules/alsa/alsa-ucm.c
@@ -653,7 +653,8 @@ static void ucm_add_port_combination(
     pa_device_port *port;
     int i;
     unsigned priority;
-    char *name, *desc;
+    char *name = NULL;
+    char *desc = NULL;
     const char *dev_name;
     const char *direction;
     pa_alsa_ucm_device *dev;
@@ -696,7 +697,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);
@@ -706,7 +711,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);
@@ -720,6 +727,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) {
-- 
1.8.1.2



More information about the pulseaudio-discuss mailing list