From c46f446fe44457f599805b685547c2258bb3fa96 Mon Sep 17 00:00:00 2001
From: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
Date: Tue, 4 Dec 2018 14:41:35 -0500
Subject: [PATCH 089/142] device-manager: free keyboards when deactivating a
 renderer

Based on an original patch by Gert van de Kraats, on Ubuntu Launchpad bug:
https://bugs.launchpad.net/ubuntu/+source/plymouth/+bug/1794292

Signed-off-by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
---
 src/libply-splash-core/ply-device-manager.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/src/libply-splash-core/ply-device-manager.c b/src/libply-splash-core/ply-device-manager.c
index d70e709..8ceee10 100644
--- a/src/libply-splash-core/ply-device-manager.c
+++ b/src/libply-splash-core/ply-device-manager.c
@@ -137,6 +137,34 @@ free_displays_for_renderer (ply_device_manager_t *manager,
 }
 
 static void
+free_keyboards_for_renderer (ply_device_manager_t *manager,
+                            ply_renderer_t       *renderer)
+{
+        ply_list_node_t *node;
+
+        node = ply_list_get_first_node (manager->keyboards);
+        while (node != NULL) {
+                ply_list_node_t *next_node;
+                ply_keyboard_t *keyboard;
+                ply_renderer_t *keyboard_renderer;
+
+                keyboard = ply_list_node_get_data (node);
+                next_node = ply_list_get_next_node (manager->keyboards, node);
+                keyboard_renderer = ply_keyboard_get_renderer (keyboard);
+
+                if (keyboard_renderer == renderer) {
+                        ply_keyboard_free (keyboard);
+                        ply_list_remove_node (manager->keyboards, node);
+                }
+
+                node = next_node;
+        }
+        if (ply_list_get_first_node (manager->keyboards) == NULL) {
+                manager->local_console_managed = false;
+        }
+}
+
+static void
 free_devices_from_device_path (ply_device_manager_t *manager,
                                const char           *device_path)
 {
@@ -152,6 +180,7 @@ free_devices_from_device_path (ply_device_manager_t *manager,
                 return;
 
         free_displays_for_renderer (manager, renderer);
+        free_keyboards_for_renderer (manager, renderer);
 
         ply_hashtable_remove (manager->renderers, (void *) device_path);
         free (key);
-- 
2.7.4

