From 1175934dec8a4147ee4ad415aa4bc84c28484c54 Mon Sep 17 00:00:00 2001 From: pfg Date: Tue, 26 Jan 2016 05:04:36 +0000 Subject: [PATCH] Revert r279011: tdelete(3): don't delete the node we are about to return. The original change, from NetBSD, was bogus; introduced a memory leak and and broke POSIX. By reverting we actually match NetBSD's latest revision. This is a revert of the original merge: this function was rewritten in 11-current. Reported by: Markiyan Kushnir Obtained from: NetBSD (CVS rev. 1.7, 1.8) git-svn-id: svn://svn.freebsd.org/base/stable/9@294763 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- lib/libc/stdlib/tdelete.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/libc/stdlib/tdelete.c b/lib/libc/stdlib/tdelete.c index bef187e81..c83afb8cf 100644 --- a/lib/libc/stdlib/tdelete.c +++ b/lib/libc/stdlib/tdelete.c @@ -14,7 +14,7 @@ #include #if 0 #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: tdelete.c,v 1.6 2012/06/25 22:32:45 abs Exp $"); +__RCSID("$NetBSD: tdelete.c,v 1.2 1999/09/16 11:45:37 lukem Exp $"); #endif /* LIBC_SCCS and not lint */ #endif __FBSDID("$FreeBSD$"); @@ -25,9 +25,9 @@ __FBSDID("$FreeBSD$"); /* - * find a node with given key + * delete node with given key * - * vkey: key to be found + * vkey: key to be deleted * vrootp: address of the root of the tree * compar: function to carry out node comparisons */ @@ -65,8 +65,7 @@ tdelete(const void * __restrict vkey, void ** __restrict vrootp, q->rlink = (*rootp)->rlink; } } - if (p != *rootp) - free(*rootp); /* D4: Free node */ + free(*rootp); /* D4: Free node */ *rootp = q; /* link parent to new node */ return p; } -- 2.45.0