wind: Handle ftruncate() and mmap() errors properly
Some checks failed
continuous-integration/drone/pr Build is failing
Some checks failed
continuous-integration/drone/pr Build is failing
This commit is contained in:
parent
e954059c79
commit
4d6ac5cf30
15
wind/IPC.cpp
15
wind/IPC.cpp
@ -26,29 +26,32 @@ static Result<u32*> create_shm_region(const char* path, int* outfd, ui::Rect rec
|
||||
int fd = shm_open(path, O_RDWR | O_CREAT | O_EXCL, 0600);
|
||||
if (fd < 0)
|
||||
{
|
||||
os::eprintln("wind: could not create shared memory region: shm_open failed (%s) - %s", path, strerror(errno));
|
||||
return err(errno);
|
||||
int olderr = errno;
|
||||
os::eprintln("wind: could not create shared memory region: shm_open failed (%s) - %s", path, strerror(olderr));
|
||||
return err(olderr);
|
||||
}
|
||||
|
||||
usize size = align_up<PAGE_SIZE>(rect.width * rect.height * 4); // 4 bytes per pixel
|
||||
|
||||
if (ftruncate(fd, size) < 0)
|
||||
{
|
||||
int olderr = errno;
|
||||
os::eprintln("wind: could not create shared memory region: ftruncate failed (%d, %zu) - %s", fd, size,
|
||||
strerror(errno));
|
||||
strerror(olderr));
|
||||
shm_unlink(path);
|
||||
close(fd);
|
||||
return 0;
|
||||
return err(olderr);
|
||||
}
|
||||
|
||||
void* p = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (p == MAP_FAILED)
|
||||
{
|
||||
int olderr = errno;
|
||||
os::eprintln("wind: could not create shared memory region: mmap failed (%zu, %d) - %s", size, fd,
|
||||
strerror(errno));
|
||||
strerror(olderr));
|
||||
shm_unlink(path);
|
||||
close(fd);
|
||||
return 0;
|
||||
return err(olderr);
|
||||
}
|
||||
|
||||
if (outfd) *outfd = fd;
|
||||
|
Loading…
Reference in New Issue
Block a user