Module Name: src Committed By: christos Date: Wed Jan 20 15:31:55 UTC 2016
Modified Files: src/lib/libc/stdlib: tdelete.c Log Message: 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? To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/lib/libc/stdlib/tdelete.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/stdlib/tdelete.c diff -u src/lib/libc/stdlib/tdelete.c:1.6 src/lib/libc/stdlib/tdelete.c:1.7 --- src/lib/libc/stdlib/tdelete.c:1.6 Mon Jun 25 18:32:45 2012 +++ src/lib/libc/stdlib/tdelete.c Wed Jan 20 10:31:55 2016 @@ -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; }