1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
From a74cfa60aadbb656dda2ec7a3ed21f319c647fef Mon Sep 17 00:00:00 2001
From: Frederik von Berg <frederikvonberg@gmail.com>
Date: Sun, 14 Aug 2022 19:58:59 +0200
Subject: [PATCH] #41 fix memory leak making owhttpd crash on concurrent
requests (analog to 4d50ca6)
---
module/owhttpd/src/c/owhttpd_handler.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/module/owhttpd/src/c/owhttpd_handler.c b/module/owhttpd/src/c/owhttpd_handler.c
index f1bd24b0d..70bddc3f0 100644
--- a/module/owhttpd/src/c/owhttpd_handler.c
+++ b/module/owhttpd/src/c/owhttpd_handler.c
@@ -543,17 +543,24 @@ enum content_type PoorMansParser( char * bad_url )
LEVEL_DEBUG("Error on http request <%s> assume html",bad_url);
return ct_html ;
}
-
+
+static regex_t rx_host;
+static pthread_once_t regex_init_once = PTHREAD_ONCE_INIT;
+
+static void regex_init(void)
+{
+ ow_regcomp( &rx_host, "host *: *([^ ]+) *\r", REG_ICASE ) ;
+}
+
static GOOD_OR_BAD GetHostURL( struct OutputControl * oc )
{
FILE * out = oc->out ;
char * line = NULL ;
- static regex_t rx_host ;
struct ow_regmatch orm ;
orm.number = 1 ;
- ow_regcomp( &rx_host, "host *: *([^ ]+) *\r", REG_ICASE ) ;
+ pthread_once(®ex_init_once, regex_init);
do {
size_t s ;
|