[vlc-devel] [PATCH 2/2] compat: tfind: fix a leak in tdelete
Alexandre Janniaux
ajanni at videolabs.io
Thu Apr 1 15:25:06 UTC 2021
Upstream has this fix, so this looks legit but can probably be
improved first.
https://github.com/NetBSD/src/commit/a9201ad704f41d40997d24a3e03dbbefc42dc39c#diff-478ad6ba5efeb09f0489bd54141f3712e9fce5361db36f0c8ee70d7b59b37962
Regards,
--
Alexandre Janniaux
Videolabs
On Thu, Apr 01, 2021 at 12:35:00PM +0200, Steve Lhomme wrote:
> In some case the root is reset to NULL (no more elements in the tree) but the
> root pointer that was allocated in the first tsearch call is not freed in that
> case.
> ---
> compat/tfind.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/compat/tfind.c b/compat/tfind.c
> index 03382f2aea5..cbb191db2f1 100644
> --- a/compat/tfind.c
> +++ b/compat/tfind.c
> @@ -69,6 +69,8 @@ tdelete(const void* vkey, void** vrootp, int (*compar)(const void*, const void*)
> }
> if (p != *rootp)
> free(*rootp); /* D4: Free node */
> + else if (q == NULL)
> + free(*rootp); /* don't leak before reset */
> *rootp = q; /* link parent to new node */
> return p;
> }
> --
> 2.29.2
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
More information about the vlc-devel
mailing list