core: fix leak in _config_data_get_main_auth_polkit()

Found by Coverity:

  Error: RESOURCE_LEAK (CWE-772):
  NetworkManager-1.31.3/src/core/nm-config-data.c:450: alloc_fn: Storage is returned from allocation function "nm_config_data_get_value".
  NetworkManager-1.31.3/src/core/nm-config-data.c:450: var_assign: Assigning: "str" = storage returned from "nm_config_data_get_value(self, "main", "auth-polkit", (enum [unnamed type of NMConfigGetValueFlags])6)".
  NetworkManager-1.31.3/src/core/nm-config-data.c:454: noescape: Resource "str" is not freed or pointed-to in "nm_auth_polkit_mode_from_string".
  NetworkManager-1.31.3/src/core/nm-config-data.c:465: leaked_storage: Variable "str" going out of scope leaks the storage it points to.
  #  463|           NM_SET_OUT(out_invalid_config, FALSE);
  #  464|
  #  465|->     return auth_polkit_mode;
  #  466|   }
  #  467|

Fixes: 6d7446e52f ('core: add main.auth-polkit option "root-only"')
This commit is contained in:
Thomas Haller 2021-05-06 18:09:22 +02:00
parent dd3aa1224a
commit ceaa1c369f
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -445,7 +445,7 @@ static NMAuthPolkitMode
_config_data_get_main_auth_polkit(const NMConfigData *self, gboolean *out_invalid_config)
{
NMAuthPolkitMode auth_polkit_mode;
const char * str;
gs_free char * str = NULL;
str = nm_config_data_get_value(self,
NM_CONFIG_KEYFILE_GROUP_MAIN,