Check return value of write function

This patch closes the file descriptor and returns with a failure,
when there is a failure.
This commit is contained in:
Steffen Moeller 2019-09-10 14:55:08 +02:00
parent 93f4dde515
commit adde78647b
1 changed files with 4 additions and 1 deletions

View File

@ -339,7 +339,10 @@ int create_shmem_mmap(const char *path, size_t size, void** pp) {
// area to all zeros because they write beyond the old EOF.
// See the lseek man page for details.
lseek(fd, size-1, SEEK_SET);
write(fd, "\0", 1);
if (1 != write(fd, "\0", 1)) {
close(fd);
return ERR_SHMGET;
}
}
*pp = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0);