From ceaa1c369f18a104f2fcda39b5b7dd6e0ce1f422 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 6 May 2021 18:09:22 +0200 Subject: [PATCH] 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: 6d7446e52f5b ('core: add main.auth-polkit option "root-only"') --- src/core/nm-config-data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/nm-config-data.c b/src/core/nm-config-data.c index 8594ed503a..94b099157c 100644 --- a/src/core/nm-config-data.c +++ b/src/core/nm-config-data.c @@ -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,