From bd0f7b022c161bf1c43bb9457925c0e1b45d0468 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Sat, 27 May 2017 15:52:32 +0200
Subject: [PATCH] server: Fix crash when a device driver segfaults during an
 open file request.

---
 server/device.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/server/device.c b/server/device.c
index 5880ea620b9..9e250a8a9d3 100644
--- a/server/device.c
+++ b/server/device.c
@@ -667,7 +667,11 @@ static void delete_device( struct device *device )
     if (!device->manager) return;  /* already deleted */
 
     LIST_FOR_EACH_ENTRY_SAFE( file, next, &device->files, struct device_file, entry )
+    {
+        grab_object( &file->obj );
         delete_file( file );
+        release_object( &file->obj );
+    }
 
     unlink_named_object( &device->obj );
     list_remove( &device->entry );
@@ -705,7 +709,9 @@ static void device_manager_destroy( struct object *obj )
     while ((ptr = list_head( &manager->devices )))
     {
         struct device *device = LIST_ENTRY( ptr, struct device, entry );
+        grab_object( &device->obj );
         delete_device( device );
+        release_object( &device->obj );
     }
 
     while ((ptr = list_head( &manager->requests )))
-- 
2.20.1

