[PATCH v3 06/18] alsa: Handle pa_device_port_new() failures

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 f4410d7..364c40c 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(
@@ -4541,6 +4549,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 {
@@ -4557,10 +4569,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



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux