From: Jaroslav Kysela Date: Wed, 12 May 2021 09:39:05 +0000 (+0200) Subject: conf: fix snd_config_substitute() - memory leak X-Git-Tag: v1.2.5~27 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=8f236983b64f5ba5ed2c68905792e367489e0316;p=alsa-lib.git 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 --- 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;