From 09c4fa5a6cae5bef38cc6d2d0a7888e22fe85802 Mon Sep 17 00:00:00 2001
From: Andrew Zaborowski <andrew.zaborowski@intel.com>
Date: Fri, 23 Oct 2020 03:47:29 +0200
Subject: [PATCH] iwd: Fix a use after free

In connection_removed we use the id.name that was being g_freed a few
lines further down.

Fixes: bea6c403677f ('wifi/iwd: handle forgetting connection profiles')
(cherry picked from commit c1ff06e11945d635c39ddaf8ec00939054fc4308)
(cherry picked from commit 03b63a893f19f6a88385f927a7386abe534c4d04)
---
 src/devices/wifi/nm-iwd-manager.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Conflict:NA
Reference:https://gitlab.freedesktop.org/NetworkManager/NetworkManager/commit/09c4fa5a6cae5bef38cc6d2d0a7888e22fe85802
diff --git a/src/devices/wifi/nm-iwd-manager.c b/src/devices/wifi/nm-iwd-manager.c
index 39c863a31e..28cae87b8c 100644
--- a/src/devices/wifi/nm-iwd-manager.c
+++ b/src/devices/wifi/nm-iwd-manager.c
@@ -634,15 +634,16 @@ connection_removed (NMSettings *settings,
 	gboolean mapped;
 	KnownNetworkData *data;
 	KnownNetworkId id;
+	gs_free char *ssid_str = NULL;
 
 	id.security = nm_wifi_connection_get_iwd_security (conn, &mapped);
 	if (!mapped)
 		return;
 
 	s_wireless = nm_connection_get_setting_wireless (conn);
-	id.name = _nm_utils_ssid_to_utf8 (nm_setting_wireless_get_ssid (s_wireless));
+	ssid_str = _nm_utils_ssid_to_utf8 (nm_setting_wireless_get_ssid (s_wireless));
+	id.name = ssid_str;
 	data = g_hash_table_lookup (priv->known_networks, &id);
-	g_free ((char *) id.name);
 	if (!data)
 		return;
 
-- 
2.23.0

