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
d535c10061
commit
56066f332f
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);
|
int fd = shm_open(path, O_RDWR | O_CREAT | O_EXCL, 0600);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
os::eprintln("wind: could not create shared memory region: shm_open failed (%s) - %s", path, strerror(errno));
|
int olderr = errno;
|
||||||
return err(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
|
usize size = align_up<PAGE_SIZE>(rect.width * rect.height * 4); // 4 bytes per pixel
|
||||||
|
|
||||||
if (ftruncate(fd, size) < 0)
|
if (ftruncate(fd, size) < 0)
|
||||||
{
|
{
|
||||||
|
int olderr = errno;
|
||||||
os::eprintln("wind: could not create shared memory region: ftruncate failed (%d, %zu) - %s", fd, size,
|
os::eprintln("wind: could not create shared memory region: ftruncate failed (%d, %zu) - %s", fd, size,
|
||||||
strerror(errno));
|
strerror(olderr));
|
||||||
shm_unlink(path);
|
shm_unlink(path);
|
||||||
close(fd);
|
close(fd);
|
||||||
return 0;
|
return err(olderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* p = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
void* p = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
if (p == MAP_FAILED)
|
if (p == MAP_FAILED)
|
||||||
{
|
{
|
||||||
|
int olderr = errno;
|
||||||
os::eprintln("wind: could not create shared memory region: mmap failed (%zu, %d) - %s", size, fd,
|
os::eprintln("wind: could not create shared memory region: mmap failed (%zu, %d) - %s", size, fd,
|
||||||
strerror(errno));
|
strerror(olderr));
|
||||||
shm_unlink(path);
|
shm_unlink(path);
|
||||||
close(fd);
|
close(fd);
|
||||||
return 0;
|
return err(olderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outfd) *outfd = fd;
|
if (outfd) *outfd = fd;
|
||||||
|
Loading…
Reference in New Issue
Block a user