mirror of
https://github.com/brl/mutter.git
synced 2024-11-22 08:00:42 -05:00
screen-cast/src: Handle failing to allocate shm buffers
Don't leak the file descriptors, and don't fall over when trying to clean up buffers that failed to allocate. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1697>
This commit is contained in:
parent
70d9a7b4bf
commit
08ad107df5
@ -781,6 +781,8 @@ on_stream_add_buffer (void *data,
|
||||
|
||||
if (ftruncate (spa_data[0].fd, spa_data[0].maxsize) < 0)
|
||||
{
|
||||
close (spa_data[0].fd);
|
||||
spa_data[0].fd = -1;
|
||||
g_critical ("Can't truncate to %d: %m", spa_data[0].maxsize);
|
||||
return;
|
||||
}
|
||||
@ -797,6 +799,8 @@ on_stream_add_buffer (void *data,
|
||||
spa_data[0].mapoffset);
|
||||
if (spa_data[0].data == MAP_FAILED)
|
||||
{
|
||||
close (spa_data[0].fd);
|
||||
spa_data[0].fd = -1;
|
||||
g_critical ("Failed to mmap memory: %m");
|
||||
return;
|
||||
}
|
||||
@ -819,11 +823,16 @@ on_stream_remove_buffer (void *data,
|
||||
g_critical ("Failed to remove non-exported DMA buffer");
|
||||
}
|
||||
else if (spa_data[0].type == SPA_DATA_MemFd)
|
||||
{
|
||||
g_warn_if_fail (spa_data[0].fd > 0 || !spa_data[0].data);
|
||||
|
||||
if (spa_data[0].fd > 0)
|
||||
{
|
||||
munmap (spa_data[0].data, spa_data[0].maxsize);
|
||||
close (spa_data[0].fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const struct pw_stream_events stream_events = {
|
||||
PW_VERSION_STREAM_EVENTS,
|
||||
|
Loading…
Reference in New Issue
Block a user