diff options
author | Davide Grohmann <davide.grohmann@arm.com> | 2022-04-25 15:27:52 +0200 |
---|---|---|
committer | Davide Grohmann <davide.grohmann@arm.com> | 2022-04-26 14:09:46 +0200 |
commit | fc49559b7800bd13652102b779adcdecccd520e3 (patch) | |
tree | d38f06eedc86ca53f5d35888d32294f51e29a93a /driver_library/src/ethosu.cpp | |
parent | 80f8ddf050d594ec663b01cb800e9547c9f919d0 (diff) | |
download | ethos-u-linux-driver-stack-fc49559b7800bd13652102b779adcdecccd520e3.tar.gz |
Fix: always close fd when destructing buffers
Also always rethrow exceptions not swallow them
Change-Id: I7a4b1e408858aa0d0128ca7bd6d6a7715662f9fb
Diffstat (limited to 'driver_library/src/ethosu.cpp')
-rw-r--r-- | driver_library/src/ethosu.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/driver_library/src/ethosu.cpp b/driver_library/src/ethosu.cpp index 01631b3..2b1da45 100644 --- a/driver_library/src/ethosu.cpp +++ b/driver_library/src/ethosu.cpp @@ -148,7 +148,7 @@ Device::Device(const char *device) { fd = eopen(device, O_RDWR | O_NONBLOCK); } -Device::~Device() { +Device::~Device() noexcept(false) { eclose(fd); } @@ -185,18 +185,21 @@ Buffer::Buffer(const Device &device, const size_t capacity) : fd(-1), dataPtr(nu try { eclose(fd); } catch (...) { std::throw_with_nested(e); } + throw; } dataPtr = reinterpret_cast<char *>(d); } -Buffer::~Buffer() { +Buffer::~Buffer() noexcept(false) { try { emunmap(dataPtr, dataCapacity); } catch (std::exception &e) { try { eclose(fd); } catch (...) { std::throw_with_nested(e); } + throw; } + eclose(fd); } size_t Buffer::capacity() const { @@ -250,6 +253,7 @@ Network::Network(const Device &device, shared_ptr<Buffer> &buffer) : fd(-1), buf try { eclose(fd); } catch (...) { std::throw_with_nested(e); } + throw; } } @@ -265,6 +269,7 @@ Network::Network(const Device &device, const unsigned index) : fd(-1) { try { eclose(fd); } catch (...) { std::throw_with_nested(e); } + throw; } } @@ -281,7 +286,7 @@ void Network::collectNetworkInfo() { } } -Network::~Network() { +Network::~Network() noexcept(false) { eclose(fd); } @@ -325,7 +330,7 @@ size_t Network::getOfmSize() const { * Inference ****************************************************************************/ -Inference::~Inference() { +Inference::~Inference() noexcept(false) { eclose(fd); } |