diff options
author | pfg <pfg@FreeBSD.org> | 2015-02-19 16:24:27 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2015-02-19 16:24:27 +0000 |
commit | 34ee2973664ba13e3589f2bb3b33cd68ccbbbac8 (patch) | |
tree | e36232381a29a84b8e2bd18431b798e7f46c5367 /lib/libc | |
parent | dd4c641aac6c3edd1451c0c0dffe811291c66105 (diff) | |
download | FreeBSD-src-34ee2973664ba13e3589f2bb3b33cd68ccbbbac8.zip FreeBSD-src-34ee2973664ba13e3589f2bb3b33cd68ccbbbac8.tar.gz |
MFC r278301, r278315:
tdelete(3): don't delete the node we are about to return.
CID: 272528
Obtained from: NetBSD (CVS rev. 1.4)
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/stdlib/tdelete.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/libc/stdlib/tdelete.c b/lib/libc/stdlib/tdelete.c index c83afb8..bef187e 100644 --- a/lib/libc/stdlib/tdelete.c +++ b/lib/libc/stdlib/tdelete.c @@ -14,7 +14,7 @@ #include <sys/cdefs.h> #if 0 #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: tdelete.c,v 1.2 1999/09/16 11:45:37 lukem Exp $"); +__RCSID("$NetBSD: tdelete.c,v 1.6 2012/06/25 22:32:45 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #endif __FBSDID("$FreeBSD$"); @@ -25,9 +25,9 @@ __FBSDID("$FreeBSD$"); /* - * delete node with given key + * find a node with given key * - * vkey: key to be deleted + * vkey: key to be found * vrootp: address of the root of the tree * compar: function to carry out node comparisons */ @@ -65,7 +65,8 @@ tdelete(const void * __restrict vkey, void ** __restrict vrootp, q->rlink = (*rootp)->rlink; } } - free(*rootp); /* D4: Free node */ + if (p != *rootp) + free(*rootp); /* D4: Free node */ *rootp = q; /* link parent to new node */ return p; } |