os: check ospoll allocation failures

ospoll_create() initializes backend-specific state immediately after
allocating the ospoll structure. Check the allocation result for each
backend before dereferencing it and return NULL on failure.

Signed-off-by: Mikhail Dmitrichenko <m.dmitrichenko222@gmail.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2217>
This commit is contained in:
Mikhail Dmitrichenko 2026-05-18 14:32:55 +03:00 committed by Marge Bot
parent 872ece04f9
commit 08e65ce8ae

View file

@ -207,6 +207,8 @@ ospoll_create(void)
{
#if POLLSET
struct ospoll *ospoll = calloc(1, sizeof (struct ospoll));
if (!ospoll)
return NULL;
ospoll->ps = pollset_create(-1);
if (ospoll->ps < 0) {
@ -217,6 +219,8 @@ ospoll_create(void)
#endif
#if PORT
struct ospoll *ospoll = calloc(1, sizeof (struct ospoll));
if (!ospoll)
return NULL;
ospoll->epoll_fd = port_create();
if (ospoll->epoll_fd < 0) {
@ -228,6 +232,8 @@ ospoll_create(void)
#endif
#if EPOLL
struct ospoll *ospoll = calloc(1, sizeof (struct ospoll));
if (!ospoll)
return NULL;
ospoll->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
if (ospoll->epoll_fd < 0) {