From 325e9cb9fa3ae51e6b3dba72d5a4a28d2b5a35fd Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Mon, 5 Oct 2020 09:00:22 +0200 Subject: [PATCH] platform_drv(x86): avoid memory leak --- .../platform/spec/x86/pci_session_component.h | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/repos/os/src/drivers/platform/spec/x86/pci_session_component.h b/repos/os/src/drivers/platform/spec/x86/pci_session_component.h index f86668348a..a7439a224d 100644 --- a/repos/os/src/drivers/platform/spec/x86/pci_session_component.h +++ b/repos/os/src/drivers/platform/spec/x86/pci_session_component.h @@ -694,11 +694,13 @@ class Platform::Session_component : public Genode::Rpc_object * A device was found. Create a new device component for the * device and return its capability. */ - try { - Device_component * dev = new (_md_alloc) - Device_component(_env, config, config_space, config_access, *this, - _md_alloc, _global_heap); + Device_component * dev = new (_md_alloc) + Device_component(_env, config, config_space, config_access, *this, + _md_alloc, _global_heap); + _device_list.insert(dev); + + try { /* if more than one driver uses the device - warn about */ if (bdf_in_use.get(Device_config::MAX_BUSES * bus + Device_config::MAX_DEVICES * device + @@ -711,14 +713,10 @@ class Platform::Session_component : public Genode::Rpc_object Device_config::MAX_DEVICES * device + function, 1); - _device_list.insert(dev); return _env.ep().rpc_ep().manage(dev); - } - catch (Genode::Out_of_ram) { - throw; - } - catch (Genode::Out_of_caps) { - Genode::warning("Out_of_caps during Device_component construction"); + } catch (...) { + _device_list.remove(dev); + destroy(_md_alloc, dev); throw; } };