From 6eef2bbb01c1de19909e7109f531b9ac24e49591 Mon Sep 17 00:00:00 2001 From: craff Date: Wed, 8 Dec 2021 16:09:16 -1000 Subject: [PATCH] catch exception in search_forward and string_match --- src/Tiny_httpd_util.ml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Tiny_httpd_util.ml b/src/Tiny_httpd_util.ml index 82b2f9db..e40295e7 100644 --- a/src/Tiny_httpd_util.ml +++ b/src/Tiny_httpd_util.ml @@ -191,18 +191,26 @@ let read_groups str groups cont = let search_forward regexp_ str ?(from=0) groups cont = let open Str in Mutex.lock str_mutex; - let _ = search_forward regexp_ str from in - let cont = read_groups str groups cont in - Mutex.unlock str_mutex; - cont + try + let _ = search_forward regexp_ str from in + let cont = read_groups str groups cont in + Mutex.unlock str_mutex; + cont + with e -> + Mutex.unlock str_mutex; + raise e let string_match regexp_ str ?(from=0) groups cont = let open Str in Mutex.lock str_mutex; - let _ = string_match regexp_ str from in - let cont = read_groups str groups cont in - Mutex.unlock str_mutex; - cont + try + let _ = string_match regexp_ str from in + let cont = read_groups str groups cont in + Mutex.unlock str_mutex; + cont + with e -> + Mutex.unlock str_mutex; + raise e let first_line str = let pos = String.index str '\n' in