diff options
author | jbj <devnull@localhost> | 2003-12-23 06:25:04 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2003-12-23 06:25:04 +0000 |
commit | db03eb6a92629e7a707a79656b79efafff98de83 (patch) | |
tree | 7749fa17e3e3cae3dfd03a17a9c789d10b5f9041 | |
parent | 945bc28d58f59e5816e10f3b7ae12f8ffe75c782 (diff) | |
download | rpm-db03eb6a92629e7a707a79656b79efafff98de83.tar.gz rpm-db03eb6a92629e7a707a79656b79efafff98de83.tar.bz2 rpm-db03eb6a92629e7a707a79656b79efafff98de83.zip |
- fix some small memory leaks (valgrind).
CVS patchset: 6998
CVS date: 2003/12/23 06:25:04
-rw-r--r-- | file/src/apprentice.c | 23 | ||||
-rw-r--r-- | file/src/softmagic.c | 2 | ||||
-rw-r--r-- | lib/formats.c | 4 | ||||
-rw-r--r-- | lib/rpmfi.c | 1 | ||||
-rw-r--r-- | lib/signature.c | 2 |
5 files changed, 19 insertions, 13 deletions
diff --git a/file/src/apprentice.c b/file/src/apprentice.c index 23f10de79..dc22a7f57 100644 --- a/file/src/apprentice.c +++ b/file/src/apprentice.c @@ -878,6 +878,7 @@ apprentice_compile(/*@unused@*/ const fmagic fm, static const uint32_t ar[] = { MAGICNO, VERSIONNO }; + int rc = -1; /* assume failure */ if (dbname == NULL) return -1; @@ -885,30 +886,34 @@ apprentice_compile(/*@unused@*/ const fmagic fm, if ((fd = open(dbname, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) { (void)fprintf(stderr, "%s: Cannot open `%s' (%s)\n", __progname, dbname, strerror(errno)); - return -1; + goto exit; } if (write(fd, ar, sizeof(ar)) != sizeof(ar)) { (void)fprintf(stderr, "%s: error writing `%s' (%s)\n", __progname, dbname, strerror(errno)); - return -1; + goto exit; } if (lseek(fd, sizeof(**magicp), SEEK_SET) != sizeof(**magicp)) { (void)fprintf(stderr, "%s: error seeking `%s' (%s)\n", __progname, dbname, strerror(errno)); - return -1; + goto exit; } if (write(fd, *magicp, sizeof(**magicp) * *nmagicp) != sizeof(**magicp) * *nmagicp) { (void)fprintf(stderr, "%s: error writing `%s' (%s)\n", __progname, dbname, strerror(errno)); - return -1; + goto exit; } + rc = 0; - (void)close(fd); - return 0; +exit: + if (fd >= 0) + (void)close(fd); + free(dbname); + return rc; } /*@=bounds@*/ @@ -934,8 +939,10 @@ apprentice_map(/*@unused@*/ const fmagic fm, if (dbname == NULL) return -1; - if ((fd = open(dbname, O_RDONLY)) == -1) + if ((fd = open(dbname, O_RDONLY)) == -1) { + free(dbname); return -1; + } if (fstat(fd, &st) == -1) { (void)fprintf(stderr, "%s: Cannot stat `%s' (%s)\n", @@ -987,9 +994,11 @@ apprentice_map(/*@unused@*/ const fmagic fm, (*magicp)++; if (needsbyteswap) byteswap(*magicp, *nmagicp); + free(dbname); return 0; errxit: + free(dbname); if (fd != -1) (void)close(fd); /*@-branchstate@*/ diff --git a/file/src/softmagic.c b/file/src/softmagic.c index 16d67f626..7c76e435b 100644 --- a/file/src/softmagic.c +++ b/file/src/softmagic.c @@ -974,7 +974,7 @@ fmagicSMatch(const fmagic fm) int cont_level = 0; int need_separator = 0; /*@only@*/ - static int32_t * tmpoff = NULL; + static int32_t * tmpoff = NULL; /* XXX memory leak */ static int tmpdelta = 64; static size_t tmplen = 0; int32_t oldoff = 0; diff --git a/lib/formats.c b/lib/formats.c index 4bab4170f..8eb21282d 100644 --- a/lib/formats.c +++ b/lib/formats.c @@ -808,12 +808,8 @@ static int filenamesTag(Header h, /*@out@*/ rpmTagType * type, /\ maxSet(count) >= 0 /\ maxSet(freeData) >= 0 @*/ { *type = RPM_STRING_ARRAY_TYPE; - rpmfiBuildFNames(h, RPMTAG_BASENAMES, (const char ***) data, count); *freeData = 1; - - *freeData = 0; /* XXX WTFO? */ - return 0; } diff --git a/lib/rpmfi.c b/lib/rpmfi.c index 63202e62f..98cfd810e 100644 --- a/lib/rpmfi.c +++ b/lib/rpmfi.c @@ -1450,6 +1450,7 @@ if (fi->actions == NULL) (void) freecon(scon); } /*@=branchstate@*/ + fi->fn = _free(fi->fn); /* Initialize array ptrs into data following array. */ len = ((fi->fc+1) * sizeof(*fi->fcontexts)) + fctxtlen; diff --git a/lib/signature.c b/lib/signature.c index a6a0eed0b..968fcb950 100644 --- a/lib/signature.c +++ b/lib/signature.c @@ -747,7 +747,7 @@ int rpmAddSignature(Header sig, const char * file, int_32 sigTag, break; case RPMSIGTAG_MD5: pktlen = 16; - pkt = xcalloc(1, pktlen); + pkt = memset(alloca(pktlen), 0, pktlen); if (domd5(file, pkt, 0, NULL) || !headerAddEntry(sig, sigTag, RPM_BIN_TYPE, pkt, pktlen)) break; |