diff options
Diffstat (limited to 'lib/dedupe-range.c')
-rw-r--r-- | lib/dedupe-range.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/dedupe-range.c b/lib/dedupe-range.c index 32296c0..016f691 100644 --- a/lib/dedupe-range.c +++ b/lib/dedupe-range.c @@ -5,7 +5,7 @@ #include <inttypes.h> /* for uint64_t, PRIu64 */ #include <linux/fs.h> /* for FIDEDUPRANGE and related */ #include <stdbool.h> /* for bool, true, false */ -#include <stdlib.h> /* for exit(3p), EXIT_SUCCESS, EXIT_FAILURE */ +#include <stdlib.h> /* for exit(3p), EXIT_SUCCESS, EXIT_FAILURE, malloc(3p), calloc(3p), free(3p) */ #include <sys/ioctl.h> /* for ioctl(2) */ #include <unistd.h> /* for sysconf(3p), _SC_PAGESIZE */ @@ -26,6 +26,8 @@ void dedupe_range(struct range src, struct range *dsts) { struct file_dedupe_range_info *range_info = calloc(dst_count, sizeof(struct file_dedupe_range_info)); + if (!range_info) + error(EXIT_FAILURE, errno, "malloc"); for (size_t i = 0; i < dst_count; i++) { int dst_fd = open(dsts[i].filename, dsts[i].flags); if (dst_fd < 0) @@ -37,6 +39,8 @@ void dedupe_range(struct range src, struct range *dsts) { for (size_t files_deduped = 0; files_deduped < dst_count; ) { uint16_t dest_count = MIN(dst_count - files_deduped, max_dst_count); struct file_dedupe_range *range = malloc(sizeof(struct file_dedupe_range) + dest_count * sizeof(struct file_dedupe_range_info)); + if (!range) + error(EXIT_FAILURE, errno, "malloc"); *range = (struct file_dedupe_range){ .src_offset = src.offset, .src_length = src.length, @@ -82,5 +86,7 @@ void dedupe_range(struct range src, struct range *dsts) { range->src_length -= bytes_deduped; } files_deduped += range->dest_count; + free(range); } + free(range_info); } |