From 6f6b58785e5f2eabc8e580fc020efdada204e270 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 1 May 2026 12:29:54 +0200 Subject: [PATCH] modules: handle allocation errors --- src/modules/module-pipe-tunnel.c | 8 ++++++++ src/modules/module-roc-sink.c | 5 ++++- src/modules/module-roc-source.c | 4 ++++ src/modules/module-snapcast-discover.c | 6 ++++++ src/modules/module-zeroconf-discover.c | 7 +++++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/modules/module-pipe-tunnel.c b/src/modules/module-pipe-tunnel.c index 8bfac4036..407d80bdf 100644 --- a/src/modules/module-pipe-tunnel.c +++ b/src/modules/module-pipe-tunnel.c @@ -664,12 +664,20 @@ static int create_fifo(struct impl *impl) impl->info.channels, impl->info.rate); impl->filename = strdup(filename); + if (impl->filename == NULL) { + res = -errno; + goto error; + } impl->unlink_fifo = do_unlink_fifo; impl->fd = fd; return 0; error: + if (impl->timer) + pw_loop_destroy_source(impl->data_loop, impl->timer); + if (impl->socket) + pw_loop_destroy_source(impl->data_loop, impl->socket); if (do_unlink_fifo) unlink(filename); if (fd >= 0) diff --git a/src/modules/module-roc-sink.c b/src/modules/module-roc-sink.c index 66a2c716b..160415717 100644 --- a/src/modules/module-roc-sink.c +++ b/src/modules/module-roc-sink.c @@ -462,7 +462,10 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args) data->remote_ip = strdup(str); } else { pw_log_error("Remote IP not specified"); - res = -EINVAL; + errno = EINVAL; + } + if (data->remote_ip == NULL) { + res = -errno; goto out; } diff --git a/src/modules/module-roc-source.c b/src/modules/module-roc-source.c index cbb40233a..e19d83b8b 100644 --- a/src/modules/module-roc-source.c +++ b/src/modules/module-roc-source.c @@ -539,6 +539,10 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args) } else { data->local_ip = strdup(PW_ROC_DEFAULT_IP); } + if (data->local_ip == NULL) { + res = -errno; + goto out; + } if ((str = pw_properties_get(props, "local.source.port")) != NULL) { data->local_source_port = pw_properties_parse_int(str); diff --git a/src/modules/module-snapcast-discover.c b/src/modules/module-snapcast-discover.c index fe4be1097..8ce133f18 100644 --- a/src/modules/module-snapcast-discover.c +++ b/src/modules/module-snapcast-discover.c @@ -323,12 +323,16 @@ static int handle_connect(struct tunnel *t, int fd) str = spa_aprintf("{\"id\":%u,\"jsonrpc\": \"2.0\",\"method\":\"Server.GetRPCVersion\"}\r\n", impl->id++); + if (str == NULL) + return -errno; res = write(t->source->fd, str, strlen(str)); pw_log_info("wrote %s: %d", str, res); free(str); str = spa_aprintf("{\"id\":%u,\"jsonrpc\":\"2.0\",\"method\":\"Stream.RemoveStream\"," "\"params\":{\"id\":\"%s\"}}\r\n", impl->id++, t->stream_name); + if (str == NULL) + return -errno; res = write(t->source->fd, str, strlen(str)); pw_log_info("wrote %s: %d", str, res); free(str); @@ -338,6 +342,8 @@ static int handle_connect(struct tunnel *t, int fd) "sampleformat=%d:%d:%d&codec=pcm&chunk_ms=20\"}}\r\n", impl->id++, t->server_address, t->stream_name, t->audio_info.rate, get_bps(t->audio_info.format), t->audio_info.channels); + if (str == NULL) + return -errno; res = write(t->source->fd, str, strlen(str)); pw_log_info("wrote %s: %d", str, res); free(str); diff --git a/src/modules/module-zeroconf-discover.c b/src/modules/module-zeroconf-discover.c index 5c1fbdd77..92f426740 100644 --- a/src/modules/module-zeroconf-discover.c +++ b/src/modules/module-zeroconf-discover.c @@ -100,6 +100,8 @@ struct tunnel { struct spa_hook module_listener; }; +static void tunnel_free(struct tunnel *t); + static struct tunnel *tunnel_new(struct impl *impl, const struct tunnel_info *info) { struct tunnel *t; @@ -112,6 +114,11 @@ static struct tunnel *tunnel_new(struct impl *impl, const struct tunnel_info *in t->info.mode = strdup(info->mode); spa_list_append(&impl->tunnel_list, &t->link); + if (t->info.name == NULL || t->info.mode == NULL) { + tunnel_free(t); + errno = ENOMEM; + return NULL; + } return t; }