[PATCH v2 19/42] vpn: Check if disconnect is implemented before calling in stop_vpn()
Jussi Laakkonen <[email protected]> Wed, 13 Aug 2025 18:01:51 +0300
| Newsgroups | dev.linux.lists.connman |
|---|---|
| Message-ID | <[email protected]> |
Check if the disconnect() is implemented for the vpn_driver before
attempting to call it when stopping a VPN. Also cleanup the code a bit.
Amends changes made in ffec305c1c93301534144774fffebb25fb9c6c7a
---
vpn/plugins/vpn.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/vpn/plugins/vpn.c b/vpn/plugins/vpn.c
index 8f04ceb6..047808b6 100644
--- a/vpn/plugins/vpn.c
+++ b/vpn/plugins/vpn.c
@@ -76,6 +76,7 @@ static int stop_vpn(struct vpn_provider *provider)
{
struct vpn_data *data = vpn_provider_get_data(provider);
struct vpn_driver_data *vpn_driver_data;
+ const struct vpn_driver *vpn_driver = NULL;
const char *name;
struct ifreq ifr;
int fd, err;
@@ -88,16 +89,19 @@ static int stop_vpn(struct vpn_provider *provider)
return -EINVAL;
vpn_driver_data = g_hash_table_lookup(driver_hash, name);
+ if (vpn_driver_data)
+ vpn_driver = vpn_driver_data->vpn_driver;
- if (vpn_driver_data && vpn_driver_data->vpn_driver &&
- vpn_driver_data->vpn_driver->flags & VPN_FLAG_NO_TUN) {
+ if (vpn_driver && vpn_driver->flags & VPN_FLAG_NO_TUN) {
/*
* Disconnect only VPNs with daemon, otherwise in error return
* there is a double free with vpn_died() or the failure state
* is overridden by changes made by disconnect to state.
*/
- if (!(vpn_driver_data->vpn_driver->flags & VPN_FLAG_NO_DAEMON))
- vpn_driver_data->vpn_driver->disconnect(data->provider);
+ if (!(vpn_driver->flags & VPN_FLAG_NO_DAEMON) &&
+ vpn_driver->disconnect)
+ vpn_driver->disconnect(data->provider);
+
return 0;
}
--
2.39.5