libnm: avoid heap allocation in _nm_utils_strdict_to_dbus()

This commit is contained in:
Thomas Haller 2019-09-22 13:33:23 +02:00
parent df6714102c
commit f36a0d408b

View file

@ -825,9 +825,15 @@ _nm_utils_strdict_to_dbus (const GValue *prop_value)
if (len == 1)
g_variant_builder_add (&builder, "{ss}", key, value);
else {
gs_free NMUtilsNamedValue *idx = NULL;
gs_free NMUtilsNamedValue *idx_free = NULL;
NMUtilsNamedValue *idx;
if (len > 300 / sizeof (NMUtilsNamedValue)) {
idx_free = g_new (NMUtilsNamedValue, len);
idx = idx_free;
} else
idx = g_alloca (sizeof (NMUtilsNamedValue) * len);
idx = g_new (NMUtilsNamedValue, len);
i = 0;
do {
idx[i].name = key;