summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2011-01-27 17:49:04 +0100
committerJim Meyering <meyering@redhat.com>2011-01-30 20:44:12 +0100
commitf5743a6f20269b22e513132d3a561b8de2122401 (patch)
tree02e32465a41bc93aa5abb69a942b92cd93e94008
parent3953f7523e560fa8afc21a82d845dbe2e2fbe1b0 (diff)
downloadcoreutils-f5743a6f20269b22e513132d3a561b8de2122401.tar.xz
fiemap copy: avoid leak-on-error
* src/copy.c (extent_copy): Don't leak an extent_scan buffer on failed lseek, read, or write.
-rw-r--r--src/copy.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/copy.c b/src/copy.c
index 9a3a8f7a6..208e4635d 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -234,6 +234,8 @@ extent_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
if (lseek (src_fd, ext_start, SEEK_SET) < 0)
{
error (0, errno, _("cannot lseek %s"), quote (src_name));
+ fail:
+ extent_scan_free (&scan);
return false;
}
@@ -242,7 +244,7 @@ extent_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
if (lseek (dest_fd, ext_start, SEEK_SET) < 0)
{
error (0, errno, _("cannot lseek %s"), quote (dst_name));
- return false;
+ goto fail;
}
}
else
@@ -257,7 +259,7 @@ extent_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
if (! write_zeros (dest_fd, hole_size))
{
error (0, errno, _("%s: write failed"), quote (dst_name));
- return false;
+ goto fail;
}
}
}
@@ -279,7 +281,7 @@ extent_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
continue;
#endif
error (0, errno, _("reading %s"), quote (src_name));
- return false;
+ goto fail;
}
if (n_read == 0)
@@ -292,7 +294,7 @@ extent_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
if (full_write (dest_fd, buf, n_read) != n_read)
{
error (0, errno, _("writing %s"), quote (dst_name));
- return false;
+ goto fail;
}
ext_len -= n_read;