Skip to content

Commit f440e51

Browse files
cjjdespresbabsingh
authored andcommitted
Use fallocate instead of ftruncate
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]>
1 parent 56cbcb6 commit f440e51

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

port/linux/omrvmem.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,8 +1164,8 @@ reserve_memory_with_mmap(struct OMRPortLibrary *portLibrary, void *address, uint
11641164
fd = mkostemp(filename, 0);
11651165
if (OMRPORT_INVALID_FD != fd) {
11661166
unlink(filename);
1167-
/* Set the file size with ftruncate. */
1168-
if (OMRPORT_INVALID_FD == ftruncate(fd, byteAmount)) {
1167+
/* Set the file size with fallocate . */
1168+
if (OMRPORT_INVALID_FD == fallocate(fd, 0, 0, byteAmount)) {
11691169
close(fd);
11701170
fd = OMRPORT_INVALID_FD;
11711171
}

0 commit comments

Comments
 (0)