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.
master
Jessie Murray 3 years ago
parent 273e2a918d
commit 03ff07252e
No known key found for this signature in database
GPG Key ID: E7E4D57EDDA744C5

@ -2,6 +2,7 @@
#include "server.h" #include "server.h"
#include "worker.h" #include "worker.h"
#include "client.h" #include "client.h"
#include "slog.h"
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -137,7 +138,11 @@ http_schedule_write(int fd, struct http_response *r) {
if(r->w) { /* async */ if(r->w) { /* async */
event_set(&r->ev, fd, EV_WRITE, http_can_write, r); event_set(&r->ev, fd, EV_WRITE, http_can_write, r);
event_base_set(r->w->base, &r->ev); 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 */ } else { /* blocking */
http_can_write(fd, 0, r); http_can_write(fd, 0, r);
} }

Loading…
Cancel
Save