From 11384211b9407eeab475e54e4806e47825fb1790 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 7 May 2022 10:11:18 -0700 Subject: [PATCH 1/2] Stop memory leak in GetResourcePixmapPath() Fixes issue reported by Oracle Parfait static analyzer: Error: Memory leak Memory leak [memory-leak] (CWE 401): Memory leak of pointer pointer allocated with XtMalloc((strlen(value.addr) + 1)) at line 700 of lib/libXaw/src/Pixmap.c in function 'GetResourcePixmapPath'. pointer allocated at line 679 with XtMalloc((strlen(value.addr) + 1)) Signed-off-by: Alan Coopersmith --- src/Pixmap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Pixmap.c b/src/Pixmap.c index 9798c9c..7072eb3 100644 --- a/src/Pixmap.c +++ b/src/Pixmap.c @@ -690,6 +690,7 @@ GetResourcePixmapPath(Display *display) length = (length + (int)strlen(tok) + 3); } } + XtFree(buffer); pixmap_path = XtRealloc(pixmap_path, (Cardinal)((size_t)length + strlen(default_path) + 2)); if (length) pixmap_path[length++] = ':'; -- GitLab From 49cec54165b46116c73e7db78c46b624948b01c8 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 7 May 2022 10:20:30 -0700 Subject: [PATCH 2/2] 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; -- GitLab