]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
http server: introduce http_paths_mutex (clang sanitizer)
authorJaroslav Kysela <perex@perex.cz>
Thu, 10 Mar 2016 17:53:48 +0000 (18:53 +0100)
committerJaroslav Kysela <perex@perex.cz>
Thu, 10 Mar 2016 17:53:48 +0000 (18:53 +0100)
src/http.c
src/http.h

index c0e3cf8c66bec510d082742f25b6e35f965b4829..66cd534bca91dfd8920561d8874ac91cea16f755 100644 (file)
@@ -46,6 +46,7 @@
 void *http_server;
 static int http_server_running;
 
+static pthread_mutex_t http_paths_mutex = PTHREAD_MUTEX_INITIALIZER;
 static http_path_list_t http_paths;
 
 static struct strtab HTTP_cmdtab[] = {
@@ -119,6 +120,7 @@ http_resolve(http_connection_t *hc, char **remainp, char **argsp)
 
   while (1) {
 
+    pthread_mutex_lock(hc->hc_paths_mutex);
     LIST_FOREACH(hp, hc->hc_paths, hp_link) {
       if(!strncmp(path, hp->hp_path, hp->hp_len)) {
         if(path[hp->hp_len] == 0 ||
@@ -127,6 +129,7 @@ http_resolve(http_connection_t *hc, char **remainp, char **argsp)
           break;
       }
     }
+    pthread_mutex_unlock(hc->hc_paths_mutex);
 
     if(hp == NULL)
       return NULL;
@@ -994,7 +997,9 @@ http_path_add_modify(const char *path, void *opaque, http_callback_t *callback,
   hp->hp_callback = callback;
   hp->hp_accessmask = accessmask;
   hp->hp_path_modify = path_modify;
+  pthread_mutex_lock(&http_paths_mutex);
   LIST_INSERT_HEAD(&http_paths, hp, hp_link);
+  pthread_mutex_unlock(&http_paths_mutex);
   return hp;
 }
 
@@ -1190,6 +1195,7 @@ http_serve(int fd, void **opaque, struct sockaddr_storage *peer,
   hc.hc_peer    = peer;
   hc.hc_self    = self;
   hc.hc_paths   = &http_paths;
+  hc.hc_paths_mutex = &http_paths_mutex;
   hc.hc_process = http_process_request;
 
   http_serve_requests(&hc);
@@ -1243,10 +1249,12 @@ http_server_done(void)
   if (http_server)
     tcp_server_delete(http_server);
   http_server = NULL;
+  pthread_mutex_lock(&http_paths_mutex);
   while ((hp = LIST_FIRST(&http_paths)) != NULL) {
     LIST_REMOVE(hp, hp_link);
     free((void *)hp->hp_path);
     free(hp);
   }
+  pthread_mutex_unlock(&http_paths_mutex);
   pthread_mutex_unlock(&global_lock);
 }
index c88f112023ff31b4062b206c4d64ab41c6502543..48157c4da6748a311e32d1bcc4cf5f3a22467441 100644 (file)
@@ -128,6 +128,7 @@ typedef struct http_connection {
   struct sockaddr_storage *hc_self;
   char *hc_representative;
 
+  pthread_mutex_t  *hc_paths_mutex;
   http_path_list_t *hc_paths;
   int (*hc_process)(struct http_connection *hc, htsbuf_queue_t *spill);