diff options
author | Mike Pechkin <mpech@cvs.openbsd.org> | 2002-01-29 08:08:58 +0000 |
---|---|---|
committer | Mike Pechkin <mpech@cvs.openbsd.org> | 2002-01-29 08:08:58 +0000 |
commit | d608d9f4dd387b7b3b72c4ddcaff7fec55fe2eeb (patch) | |
tree | dd909381d3e0c182f8ee9e680775140551d88b5a /lib/libc/gen | |
parent | 9717824dcf2caf1f06ede3ba7498dd725d48f7e7 (diff) |
Fix memory leak in setuserpath(). We prefer patch from millert@.
Diffstat (limited to 'lib/libc/gen')
-rw-r--r-- | lib/libc/gen/login_cap.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/lib/libc/gen/login_cap.c b/lib/libc/gen/login_cap.c index 54834b0c8d8..d4da2b573cc 100644 --- a/lib/libc/gen/login_cap.c +++ b/lib/libc/gen/login_cap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: login_cap.c,v 1.8 2002/01/28 07:05:03 mpech Exp $ */ +/* $OpenBSD: login_cap.c,v 1.9 2002/01/29 08:08:57 mpech Exp $ */ /*- * Copyright (c) 1995,1997 Berkeley Software Design, Inc. All rights reserved. @@ -690,20 +690,21 @@ setuserpath(lc, home) login_cap_t *lc; char *home; { - int hlen, plen; + int hlen, plen, error; int cnt = 0; char *path; - char *p, *q; + char *p, *savep; + char *q, *saveq = NULL; hlen = strlen(home); - if ((p = path = login_getcapstr(lc, "path", NULL, NULL))) { + if ((savep = p = path = login_getcapstr(lc, "path", NULL, NULL))) { while (*p) if (*p++ == '~') ++cnt; plen = (p - path) + cnt * (hlen + 1) + 1; p = path; - if ((q = path = malloc(plen))) { + if ((saveq = q = path = malloc(plen))) { while (*p) { p += strspn(p, " \t"); if (*p == '\0') @@ -726,14 +727,16 @@ setuserpath(lc, home) q += plen; } *q = '\0'; - } else - path = _PATH_DEFPATH; - } else - path = _PATH_DEFPATH; - if (setenv("PATH", path, 1)) - return (-1); + } + } + error = setenv("PATH", path ? path : _PATH_DEFPATH, 1); + + if (savep) + free(savep); + if (saveq) + free(saveq); - return (0); + return (error); } /* |