Skip to content

Commit 7ecdd2f

Browse files
committed
Wayland SHM buffer OOM fix
1 parent 1b2c241 commit 7ecdd2f

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

gfx/common/wayland_common.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,20 @@ static shm_buffer_t *create_shm_buffer(gfx_ctx_wayland_data_t *wl, int width,
545545
return NULL;
546546
}
547547

548-
buffer = calloc(1, sizeof *buffer);
548+
/* Guard the calloc before dereferencing buffer below. The
549+
* previous form immediately wrote 'buffer->wl_buffer = ...' with
550+
* no check; an OOM returning NULL from calloc would segfault.
551+
* On OOM here we also have to munmap the region and close the
552+
* fd so we do not leak them - they were both acquired above
553+
* specifically to be owned by the shm_buffer_t we are about to
554+
* return. */
555+
if (!(buffer = calloc(1, sizeof *buffer)))
556+
{
557+
RARCH_ERR("[Wayland] [SHM] Out of memory allocating shm_buffer_t.\n");
558+
munmap(data, size);
559+
close(fd);
560+
return NULL;
561+
}
549562

550563
pool = wl_shm_create_pool(wl->shm, fd, size);
551564
buffer->wl_buffer = wl_shm_pool_create_buffer(pool, 0,

0 commit comments

Comments
 (0)