summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaroslav Kysela <perex@perex.cz>2021-05-12 11:39:05 +0200
committerJaroslav Kysela <perex@perex.cz>2021-05-12 12:09:37 +0200
commit8f236983b64f5ba5ed2c68905792e367489e0316 (patch)
treedcbb1a60506b0b41f1e00efc55e1cfdb3450b5a9
parent1a52373fbc9414a8e8ec9d1470c0879e1c09fcec (diff)
downloadalsa-lib-8f236983b64f5ba5ed2c68905792e367489e0316.tar.gz
conf: fix snd_config_substitute() - memory leak
There's an issue with the current code: It says append for compounds, but it does overwrite without the proper members delete from the overwritten (destination) compound node. Don't change the behaviour, just fix the comment and memory leak. Signed-off-by: Jaroslav Kysela <perex@perex.cz>
-rw-r--r--src/conf.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/conf.c b/src/conf.c
index 1ddf7e69..c160a1fb 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -1694,8 +1694,9 @@ static int _snd_config_save_children(snd_config_t *config, snd_output_t *out,
* \param src Handle to the source node. Must not be the same as \a dst.
* \return Zero if successful, otherwise a negative error code.
*
- * If both nodes are compounds, the source compound node members are
- * appended to the destination compound node.
+ * If both nodes are compounds, the source compound node members will
+ * be moved to the destination compound node. The original destination
+ * compound node members will be deleted (overwritten).
*
* If the destination node is a compound and the source node is
* an ordinary type, the compound members are deleted (including
@@ -1710,8 +1711,13 @@ static int _snd_config_save_children(snd_config_t *config, snd_output_t *out,
int snd_config_substitute(snd_config_t *dst, snd_config_t *src)
{
assert(dst && src);
+ if (dst->type == SND_CONFIG_TYPE_COMPOUND) {
+ int err = snd_config_delete_compound_members(dst);
+ if (err < 0)
+ return err;
+ }
if (dst->type == SND_CONFIG_TYPE_COMPOUND &&
- src->type == SND_CONFIG_TYPE_COMPOUND) { /* append */
+ src->type == SND_CONFIG_TYPE_COMPOUND) { /* overwrite */
snd_config_iterator_t i, next;
snd_config_for_each(i, next, src) {
snd_config_t *n = snd_config_iterator_entry(i);
@@ -1719,11 +1725,6 @@ int snd_config_substitute(snd_config_t *dst, snd_config_t *src)
}
src->u.compound.fields.next->prev = &dst->u.compound.fields;
src->u.compound.fields.prev->next = &dst->u.compound.fields;
- } else if (dst->type == SND_CONFIG_TYPE_COMPOUND) {
- int err;
- err = snd_config_delete_compound_members(dst);
- if (err < 0)
- return err;
}
free(dst->id);
dst->id = src->id;