[vlc-devel] [PATCH 2/2] compat: tfind: fix a leak in tdelete

Steve Lhomme robux4 at ycbcr.xyz
Thu Apr 1 10:35:00 UTC 2021


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



More information about the vlc-devel mailing list