Module Name: src
Committed By: christos
Date: Fri Apr 1 19:59:08 UTC 2016
Modified Files:
src/lib/libterminfo: curterm.c termcap.c
Log Message:
- 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
To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/libterminfo/curterm.c
cvs rdiff -u -r1.18 -r1.19 src/lib/libterminfo/termcap.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/libterminfo/curterm.c
diff -u src/lib/libterminfo/curterm.c:1.11 src/lib/libterminfo/curterm.c:1.12
--- src/lib/libterminfo/curterm.c:1.11 Wed Nov 25 13:38:21 2015
+++ src/lib/libterminfo/curterm.c Fri Apr 1 15:59:08 2016
@@ -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 @@ del_curterm(TERMINAL *oterm)
free(oterm->_userdefs);
free(oterm->_buf);
free(oterm);
+ if (oterm == cur_term)
+ cur_term = NULL;
return OK;
}
Index: src/lib/libterminfo/termcap.c
diff -u src/lib/libterminfo/termcap.c:1.18 src/lib/libterminfo/termcap.c:1.19
--- src/lib/libterminfo/termcap.c:1.18 Wed Nov 25 13:46:24 2015
+++ src/lib/libterminfo/termcap.c Fri Apr 1 15:59:08 2016
@@ -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 @@ tgetent(__unused char *bp, const char *n
_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];