From 81d09ed234253aea4b93cc31d5843d2c844a51d8 Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Fri, 23 Jul 2010 18:15:18 +0200 Subject: [PATCH] Account for new evhttp behaviour on failed incoming connections The evcon associated with a request is freed by evhttp when the connection fails. Protect against a NULL evcon when handling the connection failure. --- src/httpd.c | 3 ++- src/httpd_daap.c | 7 +++++-- src/httpd_dacp.c | 7 +++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/httpd.c b/src/httpd.c index 4ce8c433..de29ad25 100644 --- a/src/httpd.c +++ b/src/httpd.c @@ -129,7 +129,8 @@ static pthread_t tid_httpd; static void stream_end(struct stream_ctx *st, int failed) { - evhttp_connection_set_closecb(st->req->evcon, NULL, NULL); + if (st->req->evcon) + evhttp_connection_set_closecb(st->req->evcon, NULL, NULL); if (!failed) evhttp_send_reply_end(st->req); diff --git a/src/httpd_daap.c b/src/httpd_daap.c index 9a9986cb..c7edf2f2 100644 --- a/src/httpd_daap.c +++ b/src/httpd_daap.c @@ -647,7 +647,8 @@ update_fail_cb(struct evhttp_connection *evcon, void *arg) DPRINTF(E_DBG, L_DAAP, "Update request: client closed connection\n"); - evhttp_connection_set_closecb(ur->req->evcon, NULL, NULL); + if (ur->req->evcon) + evhttp_connection_set_closecb(ur->req->evcon, NULL, NULL); if (ur == update_requests) update_requests = ur->next; @@ -2873,7 +2874,9 @@ daap_deinit(void) { update_requests = ur->next; - evhttp_connection_set_closecb(ur->req->evcon, NULL, NULL); + if (ur->req->evcon) + evhttp_connection_set_closecb(ur->req->evcon, NULL, NULL); + free(ur); } } diff --git a/src/httpd_dacp.c b/src/httpd_dacp.c index 8b0d53fc..dad7c26b 100644 --- a/src/httpd_dacp.c +++ b/src/httpd_dacp.c @@ -351,7 +351,8 @@ update_fail_cb(struct evhttp_connection *evcon, void *arg) DPRINTF(E_DBG, L_DACP, "Update request: client closed connection\n"); - evhttp_connection_set_closecb(ur->req->evcon, NULL, NULL); + if (ur->req->evcon) + evhttp_connection_set_closecb(ur->req->evcon, NULL, NULL); if (ur == update_requests) update_requests = ur->next; @@ -1703,7 +1704,9 @@ dacp_deinit(void) { update_requests = ur->next; - evhttp_connection_set_closecb(ur->req->evcon, NULL, NULL); + if (ur->req->evcon) + evhttp_connection_set_closecb(ur->req->evcon, NULL, NULL); + free(ur); }