From 49cec54165b46116c73e7db78c46b624948b01c8 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 7 May 2022 10:20:30 -0700 Subject: Stop memory leak in error paths in XawTextSinkConvertPropertyList() Fixes issues reported by Oracle Parfait static analyzer: Error: Memory leak Memory leak [memory-leak] (CWE 401): Memory leak of pointer pointer allocated with XtCalloc(1, 144) at line 1586 of lib/libXaw/src/TextSink.c in function 'XawTextSinkConvertPropertyList'. pointer allocated at line 1570 with XtCalloc(1, 144) pointer leaks when XawFindArgVal(params, "font") != NULL at line 1573 and argval->value != NULL at line 1574 and XLoadQueryFont(screen->display, argval->value) == NULL at line 1577. Memory leak [memory-leak] (CWE 401): Memory leak of pointer pointer allocated with XtCalloc(1, 144) at line 1605 of lib/libXaw/src/TextSink.c in function 'XawTextSinkConvertPropertyList'. pointer allocated at line 1570 with XtCalloc(1, 144) pointer leaks when argval->value == NULL at line 1574 and XawFindArgVal(params, "foreground") != NULL at line 1593 and argval->value != NULL at line 1594 and XAllocNamedColor(...) == 0 at line 1595. Memory leak [memory-leak] (CWE 401): Memory leak of pointer pointer allocated with XtCalloc(1, 144) at line 1622 of lib/libXaw/src/TextSink.c in function 'XawTextSinkConvertPropertyList'. pointer allocated at line 1570 with XtCalloc(1, 144) pointer leaks when argval->value == NULL at line 1574 and XawFindArgVal(params, "background") != NULL at line 1610 and argval->value != NULL at line 1611 and XAllocNamedColor(...) == 0 at line 1612. Signed-off-by: Alan Coopersmith --- src/TextSink.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/TextSink.c b/src/TextSink.c index d9e3f7b..3b43576 100644 --- a/src/TextSink.c +++ b/src/TextSink.c @@ -1583,6 +1583,7 @@ XawTextSinkConvertPropertyList(String name, String spec, Screen *screen, if (prev) prev->next = NULL; XawFreeParamsStruct(params); + XtFree((char *)prop); return (NULL); } prop->mask |= XAW_TPROP_FONT; @@ -1602,6 +1603,7 @@ XawTextSinkConvertPropertyList(String name, String spec, Screen *screen, if (prev) prev->next = NULL; XawFreeParamsStruct(params); + XtFree((char *)prop); return (NULL); } prop->foreground = color.pixel; @@ -1619,6 +1621,7 @@ XawTextSinkConvertPropertyList(String name, String spec, Screen *screen, if (prev) prev->next = NULL; XawFreeParamsStruct(params); + XtFree((char *)prop); return (NULL); } prop->background = color.pixel; -- cgit v1.2.1