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: de41c45e61 ('libnm-core: add functionality for dealing with tc-style traffic filter specifiers')
This commit is contained in:
Thomas Haller 2021-05-06 18:25:48 +02:00
parent 272119d925
commit 3cd56e92d4
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -2738,14 +2738,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);
@ -2785,10 +2785,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;
}