From eac55eb1b3f77c856e191a0348dd92f519d26adc Mon Sep 17 00:00:00 2001 From: cgd Date: Sat, 26 Mar 1994 02:51:45 +0000 Subject: [PATCH] slight mod --- lib/libc/gen/getcap.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c index 3e2446533561..d257a3b212a1 100644 --- a/lib/libc/gen/getcap.c +++ b/lib/libc/gen/getcap.c @@ -36,7 +36,7 @@ #if defined(LIBC_SCCS) && !defined(lint) /*static char *sccsid = "from: @(#)getcap.c 5.15 (Berkeley) 3/19/93";*/ -static char *rcsid = "$Id: getcap.c,v 1.7 1994/03/06 07:54:35 cgd Exp $"; +static char *rcsid = "$Id: getcap.c,v 1.8 1994/03/26 02:51:45 cgd Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -251,12 +251,15 @@ getent(cap, len, db_array, fd, name, depth, nfield) != NULL) { free(record); retval = cdbget(capdbp, &record, name); - clen = strlen(record); - if ((cbuf = malloc(clen + 1)) == NULL) { - errno = ENOMEM; - return (-2); + if (retval < 0) { + /* no record available */ + (void)capdbp->close(capdbp); + return (retval); } - memmove(cbuf, record, clen + 1); + /* save the data; close frees it */ + clen = strlen(record); + cbuf = malloc(clen + 1); + memcpy(cbuf, record, clen + 1); if (capdbp->close(capdbp) < 0) { free(cbuf); return (-2);