diff options
author | Thomas Haller <thaller@redhat.com> | 2021-05-06 18:25:48 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-06-04 21:29:21 +0200 |
commit | 411af763128bc530563d2ed2f6640493cf7bf530 (patch) | |
tree | f9c941011b03037ac0b8060ae8f95bdeaef1375d | |
parent | 1216fd855ca93cd0e8e2542c817191b50449a6ba (diff) | |
download | NetworkManager-411af763128bc530563d2ed2f6640493cf7bf530.tar.gz |
libnm: fix leak in nm_utils_tc_tfilter_from_str()
Found by Coverity:
Error: RESOURCE_LEAK (CWE-772):
NetworkManager-1.31.3/src/libnm-core-impl/nm-utils.c:2772: alloc_fn: Storage is returned from allocation function "nm_utils_tc_action_from_str".
NetworkManager-1.31.3/src/libnm-core-impl/nm-utils.c:2772: var_assign: Assigning: "action" = storage returned from "nm_utils_tc_action_from_str(extra_opts, error)".
NetworkManager-1.31.3/src/libnm-core-impl/nm-utils.c:2785: leaked_storage: Variable "action" going out of scope leaks the storage it points to.
# 2783| tfilter = nm_tc_tfilter_new(kind, parent, error);
# 2784| if (!tfilter)
# 2785|-> return NULL;
# 2786|
# 2787| nm_tc_tfilter_set_handle(tfilter, handle);
Fixes: de41c45e616c ('libnm-core: add functionality for dealing with tc-style traffic filter specifiers')
(cherry picked from commit 3cd56e92d4fa0fd2957094f3f46bf0e6d59cdbd5)
-rw-r--r-- | libnm-core/nm-utils.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 6ceef1e402..eebd73cfd4 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -2823,14 +2823,14 @@ static const NMVariantAttributeSpec *const tc_tfilter_attribute_spec[] = { NMTCTfilter * nm_utils_tc_tfilter_from_str(const char *str, GError **error) { - guint32 handle = TC_H_UNSPEC; - guint32 parent = TC_H_UNSPEC; - gs_free char * kind = NULL; - gs_free char * rest = NULL; - NMTCAction * action = NULL; - const char * extra_opts = NULL; - NMTCTfilter * tfilter = NULL; - gs_unref_hashtable GHashTable *ht = NULL; + guint32 handle = TC_H_UNSPEC; + guint32 parent = TC_H_UNSPEC; + gs_free char * kind = NULL; + gs_free char * rest = NULL; + nm_auto_unref_tc_action NMTCAction *action = NULL; + const char * extra_opts = NULL; + NMTCTfilter * tfilter = NULL; + gs_unref_hashtable GHashTable *ht = NULL; GVariant * variant; nm_assert(str); @@ -2870,10 +2870,8 @@ nm_utils_tc_tfilter_from_str(const char *str, GError **error) return NULL; nm_tc_tfilter_set_handle(tfilter, handle); - if (action) { + if (action) nm_tc_tfilter_set_action(tfilter, action); - nm_tc_action_unref(action); - } return tfilter; } |