From 19c6ca722d78a65c2e3c6de96b3bb4f2c2fc70fc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Mon, 20 Sep 2021 17:28:43 +0200
Subject: [PATCH] Bytecode: release the lock on dynamic.bin when an exception
 occurs

Closes: #1815
(cherry picked from commit 271d80abee97108b51a825414c7a62560f1fa744)
---
 mex/sources/bytecode/bytecode.cc | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mex/sources/bytecode/bytecode.cc b/mex/sources/bytecode/bytecode.cc
index e05fb853b2..2ab41b4561 100644
--- a/mex/sources/bytecode/bytecode.cc
+++ b/mex/sources/bytecode/bytecode.cc
@@ -723,6 +723,8 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
         }
       catch (GeneralExceptionHandling &feh)
         {
+          // Release the lock on dynamic.bin for MATLAB+Windows, see #1815
+          interprete.Close_SaveCode();
           mexErrMsgTxt(feh.GetErrorMsg().c_str());
         }
     }
@@ -734,6 +736,8 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
         }
       catch (GeneralExceptionHandling &feh)
         {
+          // Release the lock on dynamic.bin for MATLAB+Windows, see #1815
+          interprete.Close_SaveCode();
           mexErrMsgTxt(feh.GetErrorMsg().c_str());
         }
     }
-- 
GitLab