From 84b57b8d3206eab77fdcee5dfc6a2f68b3dda2b9 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 12 Oct 2024 15:55:06 -0700 Subject: [PATCH] xfree86: avoid memory leak on realloc failure Found by Oracle Parfait 13.3 static analyzer: Memory leak [memory-leak]: Memory leak of pointer optname allocated with asprintf(&optname, "\"%s\"", p->name) at line 326 of hw/xfree86/common/xf86Configure.c in function 'configureDeviceSection'. optname allocated at line 309 with asprintf(&optname, "\"%s\"", p->name) Fixes: code inherited from XFree86 Signed-off-by: Alan Coopersmith Part-of: --- hw/xfree86/common/xf86Configure.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c index 665675e91..4bd9462ba 100644 --- a/hw/xfree86/common/xf86Configure.c +++ b/hw/xfree86/common/xf86Configure.c @@ -314,8 +314,10 @@ configureDeviceSection(int screennum) len += strlen(opttype); ptr->dev_comment = realloc(ptr->dev_comment, len); - if (!ptr->dev_comment) + if (!ptr->dev_comment) { + free(optname); break; + } p_e = ptr->dev_comment + strlen(ptr->dev_comment); sprintf(p_e, "%s%-20s%s%s%s", prefix, optname, middle, opttype, suffix);