Fix resource leak if malloc of tb->data failed.
Whitespace cleanup.
This commit is contained in:
parent
dbd04f2b27
commit
8426a88bc7
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: termcap.c,v 1.48 2005/02/04 15:52:08 perry Exp $ */
|
/* $NetBSD: termcap.c,v 1.49 2006/03/18 12:18:15 blymn Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1980, 1993
|
* Copyright (c) 1980, 1993
|
||||||
@ -34,7 +34,7 @@
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)termcap.c 8.1 (Berkeley) 6/4/93";
|
static char sccsid[] = "@(#)termcap.c 8.1 (Berkeley) 6/4/93";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: termcap.c,v 1.48 2005/02/04 15:52:08 perry Exp $");
|
__RCSID("$NetBSD: termcap.c,v 1.49 2006/03/18 12:18:15 blymn Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ t_setinfo(struct tinfo **bp, const char *entry)
|
|||||||
{
|
{
|
||||||
char capability[256], *cap_ptr;
|
char capability[256], *cap_ptr;
|
||||||
size_t limit;
|
size_t limit;
|
||||||
|
|
||||||
_DIAGASSERT(bp != NULL);
|
_DIAGASSERT(bp != NULL);
|
||||||
_DIAGASSERT(entry != NULL);
|
_DIAGASSERT(entry != NULL);
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ t_setinfo(struct tinfo **bp, const char *entry)
|
|||||||
if ((*bp)->bc)
|
if ((*bp)->bc)
|
||||||
(*bp)->bc = strdup((*bp)->bc);
|
(*bp)->bc = strdup((*bp)->bc);
|
||||||
(*bp)->tbuf = NULL;
|
(*bp)->tbuf = NULL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,14 +128,14 @@ t_getent(struct tinfo **bp, const char *name)
|
|||||||
char *termpath;
|
char *termpath;
|
||||||
char capability[256], *cap_ptr;
|
char capability[256], *cap_ptr;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
|
|
||||||
_DIAGASSERT(bp != NULL);
|
_DIAGASSERT(bp != NULL);
|
||||||
_DIAGASSERT(name != NULL);
|
_DIAGASSERT(name != NULL);
|
||||||
|
|
||||||
if ((*bp = malloc(sizeof(struct tinfo))) == NULL)
|
if ((*bp = malloc(sizeof(struct tinfo))) == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fname = pathvec;
|
fname = pathvec;
|
||||||
p = pathbuf;
|
p = pathbuf;
|
||||||
cp = getenv("TERMCAP");
|
cp = getenv("TERMCAP");
|
||||||
@ -209,14 +209,14 @@ t_getent(struct tinfo **bp, const char *name)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* XXX potential security hole here in a set-id program if the
|
* XXX potential security hole here in a set-id program if the
|
||||||
* user had setup name to be built from a path they can not
|
* user had setup name to be built from a path they can not
|
||||||
* normally read.
|
* normally read.
|
||||||
*/
|
*/
|
||||||
(*bp)->info = NULL;
|
(*bp)->info = NULL;
|
||||||
i = cgetent(&((*bp)->info), (const char *const *)pathvec, name);
|
i = cgetent(&((*bp)->info), (const char *const *)pathvec, name);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if we get an error and we skipped doing the cgetset before
|
* if we get an error and we skipped doing the cgetset before
|
||||||
@ -229,7 +229,7 @@ t_getent(struct tinfo **bp, const char *name)
|
|||||||
error = -2;
|
error = -2;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
i = cgetent(&((*bp)->info), (const char *const *)pathvec, name);
|
i = cgetent(&((*bp)->info), (const char *const *)pathvec, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* no tc reference loop return code in libterm XXX */
|
/* no tc reference loop return code in libterm XXX */
|
||||||
@ -259,7 +259,7 @@ t_getent(struct tinfo **bp, const char *name)
|
|||||||
error = i + 1;
|
error = i + 1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (i + 1);
|
return (i + 1);
|
||||||
out:
|
out:
|
||||||
free(*bp);
|
free(*bp);
|
||||||
@ -275,9 +275,9 @@ tgetent(char *bp, const char *name)
|
|||||||
{
|
{
|
||||||
int i, plen, elen, c;
|
int i, plen, elen, c;
|
||||||
char *ptrbuf = NULL;
|
char *ptrbuf = NULL;
|
||||||
|
|
||||||
i = t_getent(&fbuf, name);
|
i = t_getent(&fbuf, name);
|
||||||
|
|
||||||
if (i == 1) {
|
if (i == 1) {
|
||||||
/*
|
/*
|
||||||
* stash the full buffer pointer as the ZZ capability
|
* stash the full buffer pointer as the ZZ capability
|
||||||
@ -301,7 +301,7 @@ tgetent(char *bp, const char *name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
strcat(bp, ptrbuf);
|
strcat(bp, ptrbuf);
|
||||||
tbuf = bp;
|
tbuf = bp;
|
||||||
}
|
}
|
||||||
@ -383,7 +383,7 @@ t_getstr(struct tinfo *info, const char *id, char **area, size_t *limit)
|
|||||||
*limit = 0;
|
*limit = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (area != NULL) {
|
if (area != NULL) {
|
||||||
/*
|
/*
|
||||||
* check if there is room for the new entry to be put into
|
* check if there is room for the new entry to be put into
|
||||||
@ -394,13 +394,13 @@ t_getstr(struct tinfo *info, const char *id, char **area, size_t *limit)
|
|||||||
free(s);
|
free(s);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)strcpy(*area, s);
|
(void)strcpy(*area, s);
|
||||||
free(s);
|
free(s);
|
||||||
s = *area;
|
s = *area;
|
||||||
*area += i + 1;
|
*area += i + 1;
|
||||||
if (limit != NULL) *limit -= i;
|
if (limit != NULL) *limit -= i;
|
||||||
|
|
||||||
return (s);
|
return (s);
|
||||||
} else {
|
} else {
|
||||||
_DIAGASSERT(limit != NULL);
|
_DIAGASSERT(limit != NULL);
|
||||||
@ -409,7 +409,7 @@ t_getstr(struct tinfo *info, const char *id, char **area, size_t *limit)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get a string valued option.
|
* Get a string valued option.
|
||||||
* These are given as
|
* These are given as
|
||||||
@ -428,7 +428,7 @@ tgetstr(const char *id, char **area)
|
|||||||
|
|
||||||
if (fbuf == NULL)
|
if (fbuf == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* XXX
|
* XXX
|
||||||
* This is for all the boneheaded programs that relied on tgetstr
|
* This is for all the boneheaded programs that relied on tgetstr
|
||||||
@ -460,7 +460,7 @@ t_agetstr(struct tinfo *info, const char *id)
|
|||||||
{
|
{
|
||||||
size_t new_size;
|
size_t new_size;
|
||||||
struct tbuf *tb;
|
struct tbuf *tb;
|
||||||
|
|
||||||
_DIAGASSERT(info != NULL);
|
_DIAGASSERT(info != NULL);
|
||||||
_DIAGASSERT(id != NULL);
|
_DIAGASSERT(id != NULL);
|
||||||
|
|
||||||
@ -480,8 +480,11 @@ t_agetstr(struct tinfo *info, const char *id)
|
|||||||
if ((tb = malloc(sizeof(*info->tbuf))) == NULL)
|
if ((tb = malloc(sizeof(*info->tbuf))) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ((tb->data = tb->ptr = tb->eptr = malloc(new_size)) == NULL)
|
if ((tb->data = tb->ptr = tb->eptr = malloc(new_size))
|
||||||
|
== NULL) {
|
||||||
|
free(tb);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
tb->eptr += new_size;
|
tb->eptr += new_size;
|
||||||
|
|
||||||
@ -494,7 +497,7 @@ t_agetstr(struct tinfo *info, const char *id)
|
|||||||
}
|
}
|
||||||
return t_getstr(info, id, &tb->ptr, NULL);
|
return t_getstr(info, id, &tb->ptr, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Free the buffer allocated by t_getent
|
* Free the buffer allocated by t_getent
|
||||||
*
|
*
|
||||||
@ -533,7 +536,7 @@ t_getterm(struct tinfo *info, char **area, size_t *limit)
|
|||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
count = endp - info->info + 1;
|
count = endp - info->info + 1;
|
||||||
if (area == NULL) {
|
if (area == NULL) {
|
||||||
|
Loading…
Reference in New Issue
Block a user