Skip to content

Commit

Permalink
Merge pull request #248 from cgwalters/more-analyzer
Browse files Browse the repository at this point in the history
writer: Close mmap leak
  • Loading branch information
alexlarsson authored Feb 5, 2024
2 parents e9632ca + a6904d6 commit 232336d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions libcomposefs/lcfs-writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,18 +717,21 @@ int lcfs_version_from_fd(int fd)
{
struct lcfs_erofs_header_s *header;

header = mmap(0, sizeof(struct lcfs_erofs_header_s), PROT_READ,
MAP_PRIVATE, fd, 0);
const size_t header_size = sizeof(struct lcfs_erofs_header_s);
header = mmap(0, header_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (header == MAP_FAILED) {
return -1;
}
if (lcfs_u32_from_file(header->magic) != LCFS_EROFS_MAGIC ||
lcfs_u32_from_file(header->version) != LCFS_EROFS_VERSION) {
errno = EINVAL;
munmap(header, header_size);
return -1;
}

return lcfs_u32_from_file(header->composefs_version);
int r = lcfs_u32_from_file(header->composefs_version);
munmap(header, header_size);
return r;
}

struct lcfs_node_s *lcfs_load_node_from_fd(int fd)
Expand Down

0 comments on commit 232336d

Please sign in to comment.