From 2f220c6286cdf63988aea05811db3f315abe16ea Mon Sep 17 00:00:00 2001 From: NRK Date: Wed, 28 Jun 2023 04:16:48 +0600 Subject: [PATCH] loadfile: fix leak due to setting NULL parent in the first iteration, *out will be null and thus the steal and the strdup both sets the parent to NULL - leaking the allocation later on (caught via LeakSanitizer). let append_lang() take care of setting the parent instead. --- player/loadfile.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/player/loadfile.c b/player/loadfile.c index aeca0d42a1..f11bb5bad1 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -544,6 +544,7 @@ static bool append_lang(size_t *nb, char ***out, char *in) MP_TARRAY_GROW(NULL, *out, *nb + 1); (*out)[(*nb)++] = in; (*out)[*nb] = NULL; + ta_set_parent(in, *out); return true; } @@ -552,7 +553,7 @@ static bool add_auto_langs(size_t *nb, char ***out) bool ret = false; char **autos = mp_get_user_langs(); for (int i = 0; autos && autos[i]; i++) { - if (!append_lang(nb, out, talloc_steal(*out, autos[i]))) + if (!append_lang(nb, out, autos[i])) goto cleanup; } ret = true; @@ -571,7 +572,7 @@ static char **process_langs(char **in) if (!add_auto_langs(&nb, &out)) break; } else { - if (!append_lang(&nb, &out, talloc_strdup(out, in[i]))) + if (!append_lang(&nb, &out, talloc_strdup(NULL, in[i]))) break; } }