connection_read_handler: fix potential double free

In connection_read_handler(), make sure we act accordingly when
r->connection->error is set (indicating the the current request has
been finalized).

Reproduction of what happens when we don't: enable IPRO+SPDY, and
rapidly refresh a page with chrome. These rapid abortions will
eventually trigger a segfault/hang/misc bad behaviour.
This commit is contained in:
Otto van der Schaaf
2014-09-13 16:30:34 +02:00
committed by Jeffrey Crowell
parent 6a8a1c5bf7
commit dc40c902ec
+9
View File
@@ -1281,6 +1281,15 @@ void ps_connection_read_handler(ngx_event_t* ev) {
rc = read(c->fd, chr, 256); rc = read(c->fd, chr, 256);
} while (rc > 0 || (rc == -1 && errno == EINTR)); // Retry on EINTR. } while (rc > 0 || (rc == -1 && errno == EINTR)); // Retry on EINTR.
if (r->connection->error) {
ngx_log_error(NGX_LOG_DEBUG, ngx_cycle->log, 0,
"pagespeed [%p] request already finalized", r);
ctx->pagespeed_connection = NULL;
ngx_close_connection(c);
ngx_http_finalize_request(r, NGX_ERROR);
return;
}
if (rc == -1 && errno != EAGAIN && errno != EWOULDBLOCK) { if (rc == -1 && errno != EAGAIN && errno != EWOULDBLOCK) {
ctx->pagespeed_connection = NULL; ctx->pagespeed_connection = NULL;
ngx_close_connection(c); ngx_close_connection(c);