Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
http server: introduce http_paths_mutex (clang sanitizer)
  • Loading branch information
perexg committed Mar 10, 2016
1 parent ef01fca commit 1222481
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/http.c
Expand Up @@ -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[] = {
Expand Down Expand Up @@ -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 ||
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions src/http.h
Expand Up @@ -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);

Expand Down

0 comments on commit 1222481

Please sign in to comment.