Source-Changes-HG archive

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

[src/trunk]: src/lib/libterminfo - if we are freeing cur_term, set it to NULL.



details:   https://anonhg.NetBSD.org/src/rev/c3de572ac07b
branches:  trunk
changeset: 814633:c3de572ac07b
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Apr 01 19:59:08 2016 +0000

description:
- if we are freeing cur_term, set it to NULL.
- preserve and free "last" properly.

$ cat foo.c
#include <stdio.h>
#include <termcap.h>

int
main(void)
{
        tgetent(NULL, "dumb");
        tgetent(NULL, "network");
        tgetflag("so");
        return 0;
}
$ cc foo.c -lterminfo
$ MALLOC_OPTIONS=J ./a.out
Boom.

XXX: pullup-7

diffstat:

 lib/libterminfo/curterm.c |   6 ++++--
 lib/libterminfo/termcap.c |  15 +++++++++------
 2 files changed, 13 insertions(+), 8 deletions(-)

diffs (67 lines):

diff -r ce0394ea2bcb -r c3de572ac07b lib/libterminfo/curterm.c
--- a/lib/libterminfo/curterm.c Fri Apr 01 12:37:48 2016 +0000
+++ b/lib/libterminfo/curterm.c Fri Apr 01 19:59:08 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: curterm.c,v 1.11 2015/11/25 18:38:21 christos Exp $ */
+/* $NetBSD: curterm.c,v 1.12 2016/04/01 19:59:08 christos Exp $ */
 
 /*
  * Copyright (c) 2009, 2011 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: curterm.c,v 1.11 2015/11/25 18:38:21 christos Exp $");
+__RCSID("$NetBSD: curterm.c,v 1.12 2016/04/01 19:59:08 christos Exp $");
 
 #include <assert.h>
 #include <stdlib.h>
@@ -141,6 +141,8 @@
        free(oterm->_userdefs);
        free(oterm->_buf);
        free(oterm);
+       if (oterm == cur_term)
+               cur_term = NULL;
        return OK;
 }
 
diff -r ce0394ea2bcb -r c3de572ac07b lib/libterminfo/termcap.c
--- a/lib/libterminfo/termcap.c Fri Apr 01 12:37:48 2016 +0000
+++ b/lib/libterminfo/termcap.c Fri Apr 01 19:59:08 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: termcap.c,v 1.18 2015/11/25 18:46:24 christos Exp $ */
+/* $NetBSD: termcap.c,v 1.19 2016/04/01 19:59:08 christos Exp $ */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: termcap.c,v 1.18 2015/11/25 18:46:24 christos Exp $");
+__RCSID("$NetBSD: termcap.c,v 1.19 2016/04/01 19:59:08 christos Exp $");
 
 #include <assert.h>
 #include <ctype.h>
@@ -57,14 +57,17 @@
        _DIAGASSERT(name != NULL);
 
        /* Free the old term */
-       if (last != NULL) {
-               del_curterm(last);
-               last = NULL;
+       if (cur_term != NULL) {
+               if (last != NULL && cur_term != last)
+                       del_curterm(last);
+               last = cur_term;
        }
        errret = -1;
        if (setupterm(name, STDOUT_FILENO, &errret) != 0)
                return errret;
-       last = cur_term;
+
+       if (last == NULL)
+               last = cur_term;
 
        if (pad_char != NULL)
                PC = pad_char[0];



Home | Main Index | Thread Index | Old Index