diff options
author | Thomas Haller <thaller@redhat.com> | 2021-01-14 17:38:10 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-01-14 18:12:32 +0100 |
commit | 37290c2ba5428d23f68a65d30dc6081f137ed632 (patch) | |
tree | f7925f03ce2bd255c2852582d9d3e0c99025e7ea | |
parent | fed599bb6f95e692b5f66ab3c497562bef64472c (diff) | |
download | NetworkManager-37290c2ba5428d23f68a65d30dc6081f137ed632.tar.gz |
shared: avoid heap allocation in _nm_utils_enum_from_str_full()
In the vast majority of cases is the string for _nm_utils_enum_from_str_full()
short. As we duplicate it for stripping, prefer to clone it on the stack
with nm_strdup_maybe_a().
-rw-r--r-- | shared/nm-glib-aux/nm-enum-utils.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/shared/nm-glib-aux/nm-enum-utils.c b/shared/nm-glib-aux/nm-enum-utils.c index c0f64b0c33..279eeaeb5b 100644 --- a/shared/nm-glib-aux/nm-enum-utils.c +++ b/shared/nm-glib-aux/nm-enum-utils.c @@ -212,8 +212,7 @@ _nm_utils_enum_from_str_full(GType type, _ASSERT_enum_values_info(type, value_infos); - str_clone = strdup(str); - s = nm_str_skip_leading_spaces(str_clone); + s = nm_strdup_maybe_a(300, nm_str_skip_leading_spaces(str), &str_clone); g_strchomp(s); klass = g_type_class_ref(type); |