Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/stdlib PR/50681: Markiyan Kushnir: Fix memory leak ...



details:   https://anonhg.NetBSD.org/src/rev/45f6cb1bdc2e
branches:  trunk
changeset: 343043:45f6cb1bdc2e
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Jan 20 15:31:55 2016 +0000

description:
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:

 lib/libc/stdlib/tdelete.c |  9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diffs (30 lines):

diff -r 59d3eb5582d1 -r 45f6cb1bdc2e lib/libc/stdlib/tdelete.c
--- a/lib/libc/stdlib/tdelete.c Wed Jan 20 15:26:13 2016 +0000
+++ b/lib/libc/stdlib/tdelete.c Wed Jan 20 15:31:55 2016 +0000
@@ -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 @@
                        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;
 }



Home | Main Index | Thread Index | Old Index