From df6dd17bf9a61643de404d64bc0dcd5a7c3530fc Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Mon, 8 Jun 2026 16:52:47 +0200 Subject: [PATCH] xwin: catch potential realloc() failure winInitializeScreens() In the unlikely case that realloc() fails on screen init, it's better to have a decdent error message instead of just segfault. (at that point we don't have any serious way for recovery anyways, thus FatalError() is appropriate here) X-Co-Slopped-By: BigPickle Signed-off-by: Enrico Weigelt, metux IT consult --- hw/xwin/winprocarg.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hw/xwin/winprocarg.c b/hw/xwin/winprocarg.c index 0637aeb5c7..fddc262ee7 100644 --- a/hw/xwin/winprocarg.c +++ b/hw/xwin/winprocarg.c @@ -177,9 +177,16 @@ winInitializeScreens(int maxscreens) if (maxscreens > g_iNumScreens) { /* Reallocate the memory for DDX-specific screen info */ - g_ScreenInfo = + winScreenInfo *newScreenInfo = realloc(g_ScreenInfo, maxscreens * sizeof(winScreenInfo)); + if (!newScreenInfo) { + FatalError("winInitializeScreens: realloc(%p, %d) failed\n", + (void *)g_ScreenInfo, maxscreens * (int)sizeof(winScreenInfo)); + return; + } + g_ScreenInfo = newScreenInfo; + /* Set default values for any new screens */ for (i = g_iNumScreens; i < maxscreens; i++) winInitializeScreen(i);