From 92a812e0ae99d52d89e72461f6aadf7211e706cb Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 8 Mar 2023 13:25:45 +0100 Subject: [PATCH] context: make a copy of group and link_group Just strdup the group. There is no need to keep it in a fixed size array. --- src/pipewire/context.c | 22 +++++++++++----------- src/pipewire/impl-node.c | 17 +++++++++++++---- src/pipewire/private.h | 3 ++- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/pipewire/context.c b/src/pipewire/context.c index da942c53b..0db250c0f 100644 --- a/src/pipewire/context.c +++ b/src/pipewire/context.c @@ -845,17 +845,17 @@ static int collect_nodes(struct pw_context *context, struct pw_impl_node *node, } /* now go through all the nodes that have the same group and * that are not yet visited */ - if (n->group[0] == '\0') - continue; - - spa_list_for_each(t, &context->node_list, link) { - if (t->exported || t == n || !t->active || t->visited) - continue; - if (!spa_streq(t->group, n->group)) - continue; - pw_log_debug("%p join group %s: '%s'", t, t->group, n->group); - t->visited = true; - spa_list_append(&queue, &t->sort_link); + if (n->group != NULL) { + spa_list_for_each(t, &context->node_list, link) { + if (t->exported || !t->active || t->visited) + continue; + if (!spa_streq(t->group, n->group)) + continue; + pw_log_debug("%p: %s join group %s", + t, t->name, t->group); + t->visited = true; + spa_list_append(&queue, &t->sort_link); + } } } return 0; diff --git a/src/pipewire/impl-node.c b/src/pipewire/impl-node.c index d70899036..2f8aa3b09 100644 --- a/src/pipewire/impl-node.c +++ b/src/pipewire/impl-node.c @@ -461,6 +461,8 @@ static int suspend_node(struct pw_impl_node *this) static void clear_info(struct pw_impl_node *this) { + free(this->group); + free(this->link_group); free(this->name); free((char*)this->info.error); } @@ -927,16 +929,23 @@ static void check_properties(struct pw_impl_node *node) node->rt.activation->state[0].required++; /* group defines what nodes are scheduled together */ - if ((str = pw_properties_get(node->properties, PW_KEY_NODE_GROUP)) == NULL) - str = ""; - + str = pw_properties_get(node->properties, PW_KEY_NODE_GROUP); if (!spa_streq(str, node->group)) { pw_log_info("%p: group '%s'->'%s'", node, node->group, str); - snprintf(node->group, sizeof(node->group), "%s", str); + free(node->group); + node->group = str ? strdup(str) : NULL; node->freewheel = spa_streq(node->group, "pipewire.freewheel"); recalc_reason = "group changed"; } + /* link group defines what nodes are logically linked together */ + str = pw_properties_get(node->properties, PW_KEY_NODE_LINK_GROUP); + if (!spa_streq(str, node->link_group)) { + pw_log_info("%p: link group '%s'->'%s'", node, node->link_group, str); + free(node->link_group); + node->link_group = str ? strdup(str) : NULL; + recalc_reason = "link group changed"; + } node->want_driver = pw_properties_get_bool(node->properties, PW_KEY_NODE_WANT_DRIVER, false); node->always_process = pw_properties_get_bool(node->properties, PW_KEY_NODE_ALWAYS_PROCESS, false); diff --git a/src/pipewire/private.h b/src/pipewire/private.h index 1aa02611d..ae93b0daa 100644 --- a/src/pipewire/private.h +++ b/src/pipewire/private.h @@ -672,7 +672,8 @@ struct pw_impl_node { char *name; /** for debug */ uint32_t priority_driver; /** priority for being driver */ - char group[128]; /** group to schedule this node in */ + char *group; /** group to schedule this node in */ + char *link_group; /** group this node is linked to */ uint64_t spa_flags; unsigned int registered:1;