modules: handle some more allocation errors

This commit is contained in:
Wim Taymans 2026-05-05 14:14:52 +02:00
parent 379b4a8747
commit 9946f5ec77
4 changed files with 30 additions and 0 deletions

View file

@ -352,6 +352,8 @@ static int create_stream(struct client *client)
struct spa_pod_builder b;
const char *server_id, *ip, *port, *server_name;
struct pw_properties *props = pw_properties_copy(client->props);
if (props == NULL)
return -errno;
ip = pw_properties_get(props, "sendspin.ip");
port = pw_properties_get(props, "sendspin.port");
@ -1090,6 +1092,8 @@ static void on_websocket_connected(void *data, void *user,
(struct sockaddr*)&addr, sizeof(addr));
props = pw_properties_copy(impl->stream_props);
if (props == NULL)
return;
if (pw_net_get_ip(&addr, ip, sizeof(ip), &ipv4, &port) >= 0) {
pw_properties_set(props, "sendspin.ip", ip);
pw_properties_setf(props, "sendspin.port", "%u", port);
@ -1137,6 +1141,8 @@ static void on_zeroconf_added(void *data, const void *user, const struct spa_dic
return;
props = pw_properties_copy(impl->stream_props);
if (props == NULL)
return;
pw_properties_update(props, info);
addr = spa_dict_lookup(info, PW_KEY_ZEROCONF_ADDRESS);
@ -1377,6 +1383,10 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
path = DEFAULT_SENDSPIN_PATH;
p = pw_properties_copy(impl->stream_props);
if (p == NULL) {
res = -errno;
goto out;
}
pw_properties_set(p, "sendspin.ip", hostname);
pw_properties_set(p, "sendspin.port", port);
pw_properties_set(p, "sendspin.path", path);

View file

@ -378,6 +378,8 @@ static int create_stream(struct client *c)
struct spa_pod_builder b;
const char *client_id, *ip, *port, *client_name;
struct pw_properties *props = pw_properties_copy(c->props);
if (props == NULL)
return -errno;
ip = pw_properties_get(props, "sendspin.ip");
port = pw_properties_get(props, "sendspin.port");
@ -1136,6 +1138,8 @@ static void on_websocket_connected(void *data, void *user,
(struct sockaddr*)&addr, sizeof(addr));
props = pw_properties_copy(impl->stream_props);
if (props == NULL)
return;
if (pw_net_get_ip(&addr, ip, sizeof(ip), &ipv4, &port) >= 0) {
pw_properties_set(props, "sendspin.ip", ip);
pw_properties_setf(props, "sendspin.port", "%u", port);
@ -1177,6 +1181,8 @@ static void on_zeroconf_added(void *data, const void *user, const struct spa_dic
return;
props = pw_properties_copy(impl->stream_props);
if (props == NULL)
return;
pw_properties_update(props, info);
addr = spa_dict_lookup(info, PW_KEY_ZEROCONF_ADDRESS);
@ -1405,6 +1411,10 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
while (spa_json_get_string(&iter, v, sizeof(v)) > 0) {
struct client *c;
struct pw_properties *p = pw_properties_copy(impl->stream_props);
if (p == NULL) {
res = -errno;
goto out;
}
pw_properties_set(p, "sendspin.ip", v);
pw_properties_set(p, "sendspin.port", port);

View file

@ -353,6 +353,8 @@ static int rule_matched(void *data, const char *location, const char *action,
i->matched = true;
if (spa_streq(action, "create-stream")) {
struct pw_properties *p = pw_properties_copy(i->props);
if (p == NULL)
return -errno;
pw_properties_update_string(p, str, len);
create_stream(i->stream, p);
}
@ -373,6 +375,8 @@ do_setup_stream(struct spa_loop *loop,
uint16_t port = 0;
props = pw_properties_copy(impl->stream_props);
if (props == NULL)
return -errno;
pw_net_get_ip(&s->sa, addr, sizeof(addr), NULL, &port);

View file

@ -43,6 +43,10 @@ struct pw_impl_factory *pw_context_create_factory(struct pw_context *context,
this->properties = properties;
this->info.name = strdup(name);
if (this->info.name == NULL) {
res = -errno;
goto error_free;
}
this->info.type = type;
this->info.version = version;
this->info.props = &properties->dict;
@ -55,6 +59,8 @@ struct pw_impl_factory *pw_context_create_factory(struct pw_context *context,
return this;
error_free:
free(this);
error_exit:
pw_properties_free(properties);
errno = -res;