From 5721b5b7144d7e0fa71badf4fc2666a0850ea1ee Mon Sep 17 00:00:00 2001
From: Quentin Armitage <quentin@armitage.org.uk>
Date: Mon, 27 Sep 2021 16:57:54 +0100
Subject: [PATCH] vrrp dbus: Fix assert on shutdown after name lost

When DBus reports that the VRRP name has been lost on the session
bus, keepalived calls g_hash_table_foreach_remove(). However it called
the function again on shutdown causing an assert failure. This commit
ensures that g_hash_table_foreach_remove() is not called on shutdown
if it has already been called due to the name being lost.

Signed-off-by: Quentin Armitage <quentin@armitage.org.uk>
Conflict: NA
Reference: https://github.com/acassen/keepalived/commit/5721b5b7144d7e0fa71badf4fc2666a0850ea1ee
---
 keepalived/vrrp/vrrp_dbus.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/keepalived/vrrp/vrrp_dbus.c b/keepalived/vrrp/vrrp_dbus.c
index c3b7c2c..0a223b4 100644
--- a/keepalived/vrrp/vrrp_dbus.c
+++ b/keepalived/vrrp/vrrp_dbus.c
@@ -964,8 +964,10 @@ dbus_stop(void)
 	if (!dbus_running)
 		return;
 
-	g_hash_table_foreach_remove(objects, remove_object, NULL);
-	objects = NULL;
+	if (objects) {
+		g_hash_table_foreach_remove(objects, remove_object, NULL);
+		objects = NULL;
+	}
 
 	if (global_connection != NULL) {
 		path = dbus_object_create_path_vrrp();
-- 
2.23.0

