From 03ff07252ee058154c967afcb6854137c8a1990e Mon Sep 17 00:00:00 2001 From: Jessie Murray Date: Sun, 18 Jul 2021 17:32:31 -0700 Subject: [PATCH] Clean up http_response object when write cannot be scheduled If the client closes the connection before we can even start to respond, the event_add will fail and we need to clean up the http_response object since this would have happened only after we've sent the whole response. --- src/http.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/http.c b/src/http.c index ef4ea9a..66f8135 100644 --- a/src/http.c +++ b/src/http.c @@ -2,6 +2,7 @@ #include "server.h" #include "worker.h" #include "client.h" +#include "slog.h" #include #include @@ -137,7 +138,11 @@ http_schedule_write(int fd, struct http_response *r) { if(r->w) { /* async */ event_set(&r->ev, fd, EV_WRITE, http_can_write, r); event_base_set(r->w->base, &r->ev); - event_add(&r->ev, NULL); + int ret = event_add(&r->ev, NULL); + if (ret != 0) { /* could not schedule write */ + slog(r->w->s, WEBDIS_ERROR, "Could not schedule HTTP write", 0); + http_response_cleanup(r, fd, 0); + } } else { /* blocking */ http_can_write(fd, 0, r); }