summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2016-01-20 15:31:55 +0000
committerchristos <christos@NetBSD.org>2016-01-20 15:31:55 +0000
commita9201ad704f41d40997d24a3e03dbbefc42dc39c (patch)
treecfb7b0be54a101804e2680a789665cfe4c86ef45 /lib/libc/stdlib
parent0fa7d9bb18553c487c435a65a4559ba117c408c7 (diff)
PR/50681: Markiyan Kushnir: Fix memory leak when we delete the root node.
It is questionable if we should return NULL in that case, but what is the parent of root? The new adjusted root?
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/tdelete.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/libc/stdlib/tdelete.c b/lib/libc/stdlib/tdelete.c
index 84017dc0e11..2ee05a189cb 100644
--- a/lib/libc/stdlib/tdelete.c
+++ b/lib/libc/stdlib/tdelete.c
@@ -1,4 +1,4 @@
-/* $NetBSD: tdelete.c,v 1.6 2012/06/25 22:32:45 abs Exp $ */
+/* $NetBSD: tdelete.c,v 1.7 2016/01/20 15:31:55 christos Exp $ */
/*
* Tree search generalized from Knuth (6.2.2) Algorithm T just like
@@ -13,7 +13,7 @@
#include <sys/cdefs.h>
#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.7 2016/01/20 15:31:55 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include <assert.h>
@@ -60,8 +60,9 @@ tdelete(const void *vkey, void **vrootp,
q->rlink = (*rootp)->rlink;
}
}
- if (p != *rootp)
- free(*rootp); /* D4: Free node */
+ if (p == *rootp)
+ p = NULL;
+ free(*rootp); /* D4: Free node */
*rootp = q; /* link parent to new node */
return p;
}