From 0afaaf973f110f49b978ef45abe7aa46b7fb7133 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 6 May 2021 21:39:30 +0200 Subject: [PATCH] libnmt-newt: fix leak in nmt_newt_button_build_component() Found by Coverity: Error: RESOURCE_LEAK (CWE-772): [#def274] [important] NetworkManager-1.31.3/src/libnmt-newt/nmt-newt-button.c:118: alloc_fn: Storage is returned from allocation function "g_strdup_printf". NetworkManager-1.31.3/src/libnmt-newt/nmt-newt-button.c:118: var_assign: Assigning: "label" = storage returned from "g_strdup_printf(" <%s>", priv->label)". NetworkManager-1.31.3/src/libnmt-newt/nmt-newt-button.c:119: noescape: Resource "label" is not freed or pointed-to in "nmt_newt_locale_from_utf8". NetworkManager-1.31.3/src/libnmt-newt/nmt-newt-button.c:125: leaked_storage: Variable "label" going out of scope leaks the storage it points to. # 123| } # 124| # 125|-> return co; # 126| } # 127| Fixes: 3bda3fb60c10 ('nmtui: initial import of nmtui') (cherry picked from commit 853f411567fef300b184f1745bee19f38be5cdfa) (cherry picked from commit 0a011690c4d8eb2c8b8a050476a0ad2afc11dc64) --- clients/tui/newt/nmt-newt-button.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clients/tui/newt/nmt-newt-button.c b/clients/tui/newt/nmt-newt-button.c index d3fb84bf76..b600149939 100644 --- a/clients/tui/newt/nmt-newt-button.c +++ b/clients/tui/newt/nmt-newt-button.c @@ -108,7 +108,8 @@ nmt_newt_button_build_component(NmtNewtComponent *component, gboolean sensitive) { NmtNewtButtonPrivate *priv = NMT_NEWT_BUTTON_GET_PRIVATE(component); newtComponent co; - char * label = NULL, *label_lc; + gs_free char * label = NULL; + char * label_lc; if (sensitive) { label_lc = nmt_newt_locale_from_utf8(priv->label);