diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2006-04-11 15:21:41 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2006-04-11 15:21:41 +0000 |
commit | 493ab464c7d12e52852f0a8ff6d3c26ebb9b5582 (patch) | |
tree | e42802c185062f195b1d7bc6ca51217f8afb6f9f /libexec/ld.so | |
parent | a0b5354dc1b035d441f4b608b65701a6b4648e58 (diff) |
Plug memory leaks.
Spotted by NetBSD Coverity CID 1603, improvements by jaredy@ and
otto@.
OK otto@ and millert@
Diffstat (limited to 'libexec/ld.so')
-rw-r--r-- | libexec/ld.so/ldconfig/ldconfig.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/libexec/ld.so/ldconfig/ldconfig.c b/libexec/ld.so/ldconfig/ldconfig.c index 34eef3fdfda..2cda859a3c0 100644 --- a/libexec/ld.so/ldconfig/ldconfig.c +++ b/libexec/ld.so/ldconfig/ldconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldconfig.c,v 1.17 2005/12/31 15:08:22 jmc Exp $ */ +/* $OpenBSD: ldconfig.c,v 1.18 2006/04/11 15:21:40 ray Exp $ */ /* * Copyright (c) 1993,1995 Paul Kranenburg @@ -294,7 +294,7 @@ hinthash(char *cp, int vmajor, int vminor) int buildhints(void) { - int strtab_sz = 0, nhints = 0, fd, i, n, str_index = 0; + int strtab_sz = 0, nhints = 0, fd, i, n, ret = -1, str_index = 0; struct hints_bucket *blist; struct hints_header hdr; struct shlib_list *shp; @@ -347,7 +347,7 @@ buildhints(void) } if (i == hdr.hh_nbucket) { warnx("Bummer!"); - return -1; + goto out; } while (bp->hi_next != -1) bp = &blist[bp->hi_next]; @@ -381,41 +381,45 @@ buildhints(void) tmpfile = concat(_PATH_LD_HINTS, ".XXXXXXXXXX", ""); if ((fd = mkstemp(tmpfile)) == -1) { warn("%s", tmpfile); - return -1; + goto out; } fchmod(fd, 0444); if (write(fd, &hdr, sizeof(struct hints_header)) != sizeof(struct hints_header)) { warn("%s", _PATH_LD_HINTS); - return -1; + goto out; } if (write(fd, blist, hdr.hh_nbucket * sizeof(struct hints_bucket)) != hdr.hh_nbucket * sizeof(struct hints_bucket)) { warn("%s", _PATH_LD_HINTS); - return -1; + goto out; } if (write(fd, strtab, strtab_sz) != strtab_sz) { warn("%s", _PATH_LD_HINTS); - return -1; + goto out; } if (close(fd) != 0) { warn("%s", _PATH_LD_HINTS); - return -1; + goto out; } /* Install it */ if (unlink(_PATH_LD_HINTS) != 0 && errno != ENOENT) { warn("%s", _PATH_LD_HINTS); - return -1; + goto out; } if (rename(tmpfile, _PATH_LD_HINTS) != 0) { warn("%s", _PATH_LD_HINTS); - return -1; + goto out; } - return 0; + ret = 0; +out: + free(blist); + free(strtab); + return (ret); } static int |