modules: handle allocation errors

This commit is contained in:
Wim Taymans 2026-05-01 12:29:54 +02:00
parent a55546c9df
commit 6f6b58785e
5 changed files with 29 additions and 1 deletions

View file

@ -664,12 +664,20 @@ static int create_fifo(struct impl *impl)
impl->info.channels, impl->info.rate); impl->info.channels, impl->info.rate);
impl->filename = strdup(filename); impl->filename = strdup(filename);
if (impl->filename == NULL) {
res = -errno;
goto error;
}
impl->unlink_fifo = do_unlink_fifo; impl->unlink_fifo = do_unlink_fifo;
impl->fd = fd; impl->fd = fd;
return 0; return 0;
error: 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) if (do_unlink_fifo)
unlink(filename); unlink(filename);
if (fd >= 0) if (fd >= 0)

View file

@ -462,7 +462,10 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
data->remote_ip = strdup(str); data->remote_ip = strdup(str);
} else { } else {
pw_log_error("Remote IP not specified"); pw_log_error("Remote IP not specified");
res = -EINVAL; errno = EINVAL;
}
if (data->remote_ip == NULL) {
res = -errno;
goto out; goto out;
} }

View file

@ -539,6 +539,10 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
} else { } else {
data->local_ip = strdup(PW_ROC_DEFAULT_IP); 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) { if ((str = pw_properties_get(props, "local.source.port")) != NULL) {
data->local_source_port = pw_properties_parse_int(str); data->local_source_port = pw_properties_parse_int(str);

View file

@ -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", str = spa_aprintf("{\"id\":%u,\"jsonrpc\": \"2.0\",\"method\":\"Server.GetRPCVersion\"}\r\n",
impl->id++); impl->id++);
if (str == NULL)
return -errno;
res = write(t->source->fd, str, strlen(str)); res = write(t->source->fd, str, strlen(str));
pw_log_info("wrote %s: %d", str, res); pw_log_info("wrote %s: %d", str, res);
free(str); free(str);
str = spa_aprintf("{\"id\":%u,\"jsonrpc\":\"2.0\",\"method\":\"Stream.RemoveStream\"," str = spa_aprintf("{\"id\":%u,\"jsonrpc\":\"2.0\",\"method\":\"Stream.RemoveStream\","
"\"params\":{\"id\":\"%s\"}}\r\n", impl->id++, t->stream_name); "\"params\":{\"id\":\"%s\"}}\r\n", impl->id++, t->stream_name);
if (str == NULL)
return -errno;
res = write(t->source->fd, str, strlen(str)); res = write(t->source->fd, str, strlen(str));
pw_log_info("wrote %s: %d", str, res); pw_log_info("wrote %s: %d", str, res);
free(str); 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++, "sampleformat=%d:%d:%d&codec=pcm&chunk_ms=20\"}}\r\n", impl->id++,
t->server_address, t->stream_name, t->audio_info.rate, t->server_address, t->stream_name, t->audio_info.rate,
get_bps(t->audio_info.format), t->audio_info.channels); get_bps(t->audio_info.format), t->audio_info.channels);
if (str == NULL)
return -errno;
res = write(t->source->fd, str, strlen(str)); res = write(t->source->fd, str, strlen(str));
pw_log_info("wrote %s: %d", str, res); pw_log_info("wrote %s: %d", str, res);
free(str); free(str);

View file

@ -100,6 +100,8 @@ struct tunnel {
struct spa_hook module_listener; 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) static struct tunnel *tunnel_new(struct impl *impl, const struct tunnel_info *info)
{ {
struct tunnel *t; 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); t->info.mode = strdup(info->mode);
spa_list_append(&impl->tunnel_list, &t->link); 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; return t;
} }