From 853f411567fef300b184f1745bee19f38be5cdfa 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') --- src/libnmt-newt/nmt-newt-button.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libnmt-newt/nmt-newt-button.c b/src/libnmt-newt/nmt-newt-button.c index 09ca1648a8..4518499b86 100644 --- a/src/libnmt-newt/nmt-newt-button.c +++ b/src/libnmt-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);