diff options
author | Karel Zak | 2013-03-27 16:13:39 +0100 |
---|---|---|
committer | Karel Zak | 2013-03-27 16:15:37 +0100 |
commit | 985b351ed8ec1d7ce7aeebca27cc7c88571a5657 (patch) | |
tree | 183794c1b94860d4a6b261e8fc952a0b126912d0 /disk-utils/mkfs.cramfs.c | |
parent | lib/xalloc: fix mamory leak in xgethostname() [coverity scan] (diff) | |
download | kernel-qcow2-util-linux-985b351ed8ec1d7ce7aeebca27cc7c88571a5657.tar.gz kernel-qcow2-util-linux-985b351ed8ec1d7ce7aeebca27cc7c88571a5657.tar.xz kernel-qcow2-util-linux-985b351ed8ec1d7ce7aeebca27cc7c88571a5657.zip |
mkfs.cramfs: fix memory leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/mkfs.cramfs.c')
-rw-r--r-- | disk-utils/mkfs.cramfs.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/disk-utils/mkfs.cramfs.c b/disk-utils/mkfs.cramfs.c index 8abc0455d..94f0c3397 100644 --- a/disk-utils/mkfs.cramfs.c +++ b/disk-utils/mkfs.cramfs.c @@ -144,7 +144,7 @@ usage(int status) { static char * do_mmap(char *path, unsigned int size, unsigned int mode){ int fd; - char *start; + char *start = NULL; if (!size) return NULL; @@ -152,26 +152,31 @@ do_mmap(char *path, unsigned int size, unsigned int mode){ if (S_ISLNK(mode)) { start = xmalloc(size); if (readlink(path, start, size) < 0) { - perror(path); + warn(_("readlink failed: %s"), path); warn_skip = 1; - start = NULL; + goto err; } return start; } fd = open(path, O_RDONLY); if (fd < 0) { - perror(path); + warn(_("open failed: %s"), path); warn_skip = 1; - return NULL; + goto err; } start = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); - if (-1 == (int) (long) start) + if (-1 == (int) (long) start) { + free(start); + close(fd); err(MKFS_EX_ERROR, "mmap"); + } close(fd); - return start; +err: + free(start); + return NULL; } static void |