Skip to content

Commit

Permalink
Use fallocate instead of ftruncate
Browse files Browse the repository at this point in the history
Even if the ftruncate() system call succeeds, this does not guarantee
that the underlying filesystem has enough free blocks to support
whatever increase in file size that was requested. This can cause SIGBUS
errors if writes are attempted in the file.

The fallocate() call does guarantee that there is enough space
available.

Signed-off-by: Christian Despres <[email protected]>
  • Loading branch information
cjjdespres authored and babsingh committed Oct 22, 2024
1 parent 56cbcb6 commit f440e51
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions port/linux/omrvmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1164,8 +1164,8 @@ reserve_memory_with_mmap(struct OMRPortLibrary *portLibrary, void *address, uint
fd = mkostemp(filename, 0);
if (OMRPORT_INVALID_FD != fd) {
unlink(filename);
/* Set the file size with ftruncate. */
if (OMRPORT_INVALID_FD == ftruncate(fd, byteAmount)) {
/* Set the file size with fallocate . */
if (OMRPORT_INVALID_FD == fallocate(fd, 0, 0, byteAmount)) {
close(fd);
fd = OMRPORT_INVALID_FD;
}
Expand Down

0 comments on commit f440e51

Please sign in to comment.