diff mbox series

[4/9] confmisc: fix memory leak in snd_func_concat

Message ID 20201226213547.175071-5-alexhenrie24@gmail.com (mailing list archive)
State New, archived
Headers show
Series scan-build fixes | expand

Commit Message

Alex Henrie Dec. 26, 2020, 9:35 p.m. UTC
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
 src/confmisc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Takashi Iwai Dec. 27, 2020, 8:26 a.m. UTC | #1
On Sat, 26 Dec 2020 22:35:42 +0100,
Alex Henrie wrote:
> 
> Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
> ---
>  src/confmisc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/confmisc.c b/src/confmisc.c
> index eb8218c1..aece39c3 100644
> --- a/src/confmisc.c
> +++ b/src/confmisc.c
> @@ -440,8 +440,8 @@ int snd_func_concat(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
>  	err = snd_config_get_id(src, &id);
>  	if (err >= 0)
>  		err = snd_config_imake_string(dst, id, res);
> -	free(res);
>        __error:
> +	free(res);
>  	return err;
>  }
>  #ifndef DOC_HIDDEN

I guess this would lead to the double-free at the error path after
realloc() that already freed res before the goto line.
Care to fix it and resubmit this one?


thanks,

Takashi
Alex Henrie Dec. 28, 2020, 1:45 a.m. UTC | #2
On Sun, Dec 27, 2020 at 1:26 AM Takashi Iwai <tiwai@suse.de> wrote:
>
> I guess this would lead to the double-free at the error path after
> realloc() that already freed res before the goto line.
> Care to fix it and resubmit this one?

Thank you for catching that! I just sent a v2 of this patch.

-Alex
diff mbox series

Patch

diff --git a/src/confmisc.c b/src/confmisc.c
index eb8218c1..aece39c3 100644
--- a/src/confmisc.c
+++ b/src/confmisc.c
@@ -440,8 +440,8 @@  int snd_func_concat(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
 	err = snd_config_get_id(src, &id);
 	if (err >= 0)
 		err = snd_config_imake_string(dst, id, res);
-	free(res);
       __error:
+	free(res);
 	return err;
 }
 #ifndef DOC_HIDDEN