comparison src/event/ngx_event_pipe.c @ 1099:04a8b485447d

fix segfault when a large FastCGI response was written to a temporary file
author Igor Sysoev <igor@sysoev.ru>
date Fri, 09 Feb 2007 14:02:42 +0000
parents 1ade5def878d
children 37c3b4e62b03
comparison
equal deleted inserted replaced
1098:aed9dfe2a4f2 1099:04a8b485447d
417 417
418 418
419 static ngx_int_t 419 static ngx_int_t
420 ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p) 420 ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p)
421 { 421 {
422 u_char *prev;
422 size_t bsize; 423 size_t bsize;
423 ngx_uint_t flush, prev_last_shadow; 424 ngx_uint_t flush, prev_last_shadow;
424 ngx_chain_t *out, **ll, *cl; 425 ngx_chain_t *out, **ll, *cl;
425 ngx_connection_t *downstream; 426 ngx_connection_t *downstream;
426 427
495 break; 496 break;
496 } 497 }
497 498
498 /* bsize is the size of the busy recycled bufs */ 499 /* bsize is the size of the busy recycled bufs */
499 500
501 prev = NULL;
500 bsize = 0; 502 bsize = 0;
501 503
502 for (cl = p->busy; cl; cl = cl->next) { 504 for (cl = p->busy; cl; cl = cl->next) {
505 if (prev == cl->buf->start) {
506 continue;
507 }
508
503 if (cl->buf->recycled) { 509 if (cl->buf->recycled) {
504 bsize += cl->buf->end - cl->buf->start; 510 bsize += cl->buf->end - cl->buf->start;
511 prev = cl->buf->start;
505 } 512 }
506 } 513 }
507 514
508 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, 515 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
509 "pipe write busy: %uz", bsize); 516 "pipe write busy: %uz", bsize);
510 517
511 out = NULL; 518 out = NULL;
519
520 if (bsize >= (size_t) p->busy_size) {
521 flush = 1;
522 goto flush;
523 }
524
525 flush = 0;
512 ll = NULL; 526 ll = NULL;
513 flush = 0;
514 prev_last_shadow = 1; 527 prev_last_shadow = 1;
515 528
516 for ( ;; ) { 529 for ( ;; ) {
517 if (p->out) { 530 if (p->out) {
518 cl = p->out; 531 cl = p->out;
577 out = cl; 590 out = cl;
578 } 591 }
579 ll = &cl->next; 592 ll = &cl->next;
580 } 593 }
581 594
595 flush:
596
582 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0, 597 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0,
583 "pipe write: out:%p, f:%d", out, flush); 598 "pipe write: out:%p, f:%d", out, flush);
584 599
585 if (out == NULL && !flush) { 600 if (out == NULL && !flush) {
586 break; 601 break;