Fix: do not leak file descriptors on errors

When bailing out on errors in the constructors of Buffers or Networks,
the open file descriptor should be closed since the descructor will
never be called.

Change-Id: I8e1954e9efd65b594cc9544e18d0bfbe0730f156
diff --git a/driver_library/src/ethosu.cpp b/driver_library/src/ethosu.cpp
index 45e8525..4fc431b 100644
--- a/driver_library/src/ethosu.cpp
+++ b/driver_library/src/ethosu.cpp
@@ -233,7 +233,14 @@
     ethosu_uapi_buffer_create uapi = {static_cast<uint32_t>(dataCapacity)};
     fd                             = device.ioctl(ETHOSU_IOCTL_BUFFER_CREATE, static_cast<void *>(&uapi));
 
-    void *d = emmap(nullptr, dataCapacity, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+    void *d;
+    try {
+        d = emmap(nullptr, dataCapacity, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+    } catch (std::exception &e) {
+        try {
+            eclose(fd);
+        } catch (...) { std::throw_with_nested(e); }
+    }
     dataPtr = reinterpret_cast<char *>(d);
 }
 
@@ -291,7 +298,9 @@
     const tflite::Model *model = tflite::GetModel(reinterpret_cast<void *>(buffer->data()));
 
     if (model->subgraphs() == nullptr) {
-        throw EthosU::Exception("Failed to get subgraphs: nullptr");
+        try {
+            eclose(fd);
+        } catch (...) { std::throw_with_nested(EthosU::Exception("Failed to get subgraphs: nullptr")); }
     }
 
     // Get input dimensions for first subgraph