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: 3bda3fb60c ('nmtui: initial import of nmtui')
This commit is contained in:
Thomas Haller 2021-05-06 21:39:30 +02:00
parent 2c628e4762
commit 853f411567
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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);