From 88a7ec8b145b915436045baa89fd178ae03ee128 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 14 Jan 2021 17:38:10 +0100 Subject: [PATCH] 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(). --- shared/nm-glib-aux/nm-enum-utils.c | 3 +-- 1 file changed, 1 insertion(+), 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);