From: Jaroslav Kysela Date: Wed, 9 Dec 2015 14:43:36 +0000 (+0100) Subject: httpc: try to fix no-locking data race X-Git-Tag: v4.2.1~1332 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fe15abf043c8fbe534bf9726176f0df17450e088;p=thirdparty%2Ftvheadend.git httpc: try to fix no-locking data race --- diff --git a/src/httpc.c b/src/httpc.c index f132ba005..e83367b7c 100644 --- a/src/httpc.c +++ b/src/httpc.c @@ -126,7 +126,6 @@ static void http_client_shutdown ( http_client_t *hc, int force, int reconnect ) { struct http_client_ssl *ssl = hc->hc_ssl; - tvhpoll_t *efd = NULL; hc->hc_shutdown = 1; if (ssl) { @@ -142,7 +141,7 @@ http_client_shutdown ( http_client_t *hc, int force, int reconnect ) tvhpoll_event_t ev; memset(&ev, 0, sizeof(ev)); ev.fd = hc->hc_fd; - tvhpoll_rem(efd = hc->hc_efd, &ev, 1); + tvhpoll_rem(hc->hc_efd, &ev, 1); if (hc->hc_efd == http_poll && !reconnect) { pthread_mutex_lock(&http_lock); TAILQ_REMOVE(&http_clients, hc, hc_link); @@ -1525,6 +1524,7 @@ void http_client_close ( http_client_t *hc ) { http_client_wcmd_t *wcmd; + tvhpoll_event_t ev; if (hc == NULL) return; @@ -1534,6 +1534,11 @@ http_client_close ( http_client_t *hc ) hc->hc_shutdown_wait = 1; while (hc->hc_running) pthread_cond_wait(&http_cond, &http_lock); + memset(&ev, 0, sizeof(ev)); + ev.fd = hc->hc_fd; + tvhpoll_rem(hc->hc_efd, &ev, 1); + TAILQ_REMOVE(&http_clients, hc, hc_link); + hc->hc_efd = NULL; pthread_mutex_unlock(&http_lock); } http_client_shutdown(hc, 1, 0);