summaryrefslogtreecommitdiff
path: root/file/src
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2003-12-23 06:25:04 +0000
committerjbj <devnull@localhost>2003-12-23 06:25:04 +0000
commitdb03eb6a92629e7a707a79656b79efafff98de83 (patch)
tree7749fa17e3e3cae3dfd03a17a9c789d10b5f9041 /file/src
parent945bc28d58f59e5816e10f3b7ae12f8ffe75c782 (diff)
downloadlibrpm-tizen-db03eb6a92629e7a707a79656b79efafff98de83.tar.gz
librpm-tizen-db03eb6a92629e7a707a79656b79efafff98de83.tar.bz2
librpm-tizen-db03eb6a92629e7a707a79656b79efafff98de83.zip
- fix some small memory leaks (valgrind).
CVS patchset: 6998 CVS date: 2003/12/23 06:25:04
Diffstat (limited to 'file/src')
-rw-r--r--file/src/apprentice.c23
-rw-r--r--file/src/softmagic.c2
2 files changed, 17 insertions, 8 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;