From 111ca8af21c4c93f20a18596cf5df4dbf4c1c391 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 7 May 2025 15:08:03 +0200 Subject: [PATCH] xfree86: utils: gracefully handle allocation failure. Better failing gracefully instead of hard crash via segfault. Signed-off-by: Enrico Weigelt, metux IT consult --- hw/xfree86/utils/gtf/gtf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/xfree86/utils/gtf/gtf.c b/hw/xfree86/utils/gtf/gtf.c index 818ee0fd7..2e5ebea71 100644 --- a/hw/xfree86/utils/gtf/gtf.c +++ b/hw/xfree86/utils/gtf/gtf.c @@ -294,7 +294,9 @@ vert_refresh(int h_pixels, int v_lines, float freq, int interlaced, int margins) float h_front_porch; float v_odd_front_porch_lines; - mode *m = (mode *) malloc(sizeof(mode)); + mode *m = (mode *) calloc(1, sizeof(mode)); + if (!m) + return NULL; /* 1. In order to give correct results, the number of horizontal * pixels requested is first processed to ensure that it is divisible @@ -604,6 +606,8 @@ parse_command_line(int argc, char *argv[]) int n; options *o = (options *) calloc(1, sizeof(options)); + if (!o) + goto bad_option; if (argc < 4) goto bad_option;