From a8813ff6fe179abdde47597fdd557b1b0730372a Mon Sep 17 00:00:00 2001 From: Ratchanan Srirattanamet Date: Mon, 10 Oct 2022 02:06:12 +0700 Subject: [PATCH] wwan/ofono: fix memory leak in handle_settings() [thaller@redhat.com: modified original patch.] Fixes: 58287cbcc0c8 ('core: rework IP configuration in NetworkManager using layer 3 configuration') (cherry picked from commit 61e99ed715377f0398c6fc57cd2fb02e34b19b66) --- src/core/devices/wwan/nm-modem-ofono.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/devices/wwan/nm-modem-ofono.c b/src/core/devices/wwan/nm-modem-ofono.c index c003880e6c..fc27c3fd44 100644 --- a/src/core/devices/wwan/nm-modem-ofono.c +++ b/src/core/devices/wwan/nm-modem-ofono.c @@ -739,7 +739,7 @@ handle_settings(GVariant *v_dict, gpointer user_data) gboolean ret = FALSE; const char *interface; const char *s; - const char **array; + gs_free const char **array = NULL; guint32 address_network, gateway_network; int ifindex; GError *error = NULL; @@ -838,15 +838,16 @@ handle_settings(GVariant *v_dict, gpointer user_data) } if (array) { gboolean any_good = FALSE; + gsize i; - for (; array[0]; array++) { - if (!nm_utils_parse_inaddr_bin(AF_INET, *array, NULL, &address_network) + for (i = 0; array[i]; i++) { + if (!nm_utils_parse_inaddr_bin(AF_INET, array[i], NULL, &address_network) || !address_network) { - _LOGW("invalid NameServer: %s", *array); + _LOGW("invalid NameServer: %s", array[i]); continue; } any_good = TRUE; - _LOGI("DNS: %s", *array); + _LOGI("DNS: %s", array[i]); nm_l3_config_data_add_nameserver(priv->l3cd_4, AF_INET, &address_network); } if (!any_good) {