diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libterm/termcap.3 | 12 | ||||
-rw-r--r-- | lib/libterm/termcap.c | 8 |
2 files changed, 17 insertions, 3 deletions
diff --git a/lib/libterm/termcap.3 b/lib/libterm/termcap.3 index e5b1db0b79e..a92207ce46e 100644 --- a/lib/libterm/termcap.3 +++ b/lib/libterm/termcap.3 @@ -85,6 +85,18 @@ should be a character buffer of size .Fn tgetflag , and .Fn tgetstr . +As an extension +.Fn tgetent +can be passed NULL +for the +.Fa bp +argument, in which case an internal buffer will be used. +If repeated calls to +.Fn tgetent +is made with a NULL +.Fa bp +argument, some memory will be leaked on each call subsequent +to the first. The .Fn tgetent function diff --git a/lib/libterm/termcap.c b/lib/libterm/termcap.c index 2109744f990..2eb5d31cdd9 100644 --- a/lib/libterm/termcap.c +++ b/lib/libterm/termcap.c @@ -139,16 +139,18 @@ tgetent(bp, name) dummy = NULL; i = cgetent(&dummy, pathvec, name); - if (i == 0) { + if (i == 0 && bp != NULL) { strncpy(bp, dummy, 1023); bp[1023] = '\0'; if ((cp = strrchr(bp, ':')) != NULL) if (cp[1] != '\0') cp[1] = '\0'; } - - if (dummy) + else if (i == 0 && bp == NULL) + tbuf = dummy; + else if (dummy != NULL) free(dummy); + /* no tc reference loop return code in libterm XXX */ if (i == -3) return (-1); |