Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

writer: Close mmap leak #248

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading