From 90d84416821bfa9c6dce0dd10a7affa76b3e57f8 Mon Sep 17 00:00:00 2001 From: think Date: Sun, 19 Nov 2017 09:28:14 +0100 Subject: [PATCH 1/2] avoid double closing file in case of error --- src/vectorflow/neuralnet.d | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/vectorflow/neuralnet.d b/src/vectorflow/neuralnet.d index 41e5d1e..1f6cc3b 100644 --- a/src/vectorflow/neuralnet.d +++ b/src/vectorflow/neuralnet.d @@ -590,10 +590,8 @@ class NeuralNet { void serialize(string path) { auto f = File(path, "w"); - scope(exit) f.close(); scope(failure) { - f.close(); try { writeln("Serialization failed."); @@ -605,6 +603,7 @@ class NeuralNet { "` after serialization failure: ", e); } } + scope(exit) f.close(); auto ser = new Serializer(&f); From 4c7cbd7ae3bf3b8fd21f8f98786d0e017b638a2b Mon Sep 17 00:00:00 2001 From: think Date: Mon, 20 Nov 2017 18:57:25 +0100 Subject: [PATCH 2/2] removed all file.close() calls, cause file gets closed when scope is left --- src/vectorflow/neuralnet.d | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/vectorflow/neuralnet.d b/src/vectorflow/neuralnet.d index 1f6cc3b..f7cb302 100644 --- a/src/vectorflow/neuralnet.d +++ b/src/vectorflow/neuralnet.d @@ -603,7 +603,6 @@ class NeuralNet { "` after serialization failure: ", e); } } - scope(exit) f.close(); auto ser = new Serializer(&f); @@ -639,9 +638,6 @@ class NeuralNet { if(!exists(path)) throw new Exception("File does not exists: " ~ path); auto f = File(path, "r"); - scope(exit) f.close(); - scope(failure) f.close(); - auto nn = new NeuralNet(); auto deser = new Serializer(&f);