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 <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1730>
This commit is contained in:
Alan Coopersmith 2024-10-12 15:55:06 -07:00 committed by Marge Bot
parent 45c485bfdf
commit fa711c486a

View File

@ -313,8 +313,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);