Commit 99243a4b authored by Wandenberg's avatar Wandenberg

ensure that buffers content will not be changed and the allocated memory is clean

parent 8147b89e
......@@ -139,6 +139,7 @@ ngx_http_push_stream_send_response_channels_info(ngx_http_request_t *r, ngx_queu
chain->buf->last_buf = 0;
chain->buf->memory = 1;
chain->buf->temporary = 0;
chain->buf->pos = text->data;
chain->buf->last = text->data + text->len;
chain->buf->start = chain->buf->pos;
......
......@@ -158,6 +158,8 @@ ngx_http_push_stream_read_request_body_to_buffer(ngx_http_request_t *r)
buf = ngx_create_temp_buf(r->pool, r->headers_in.content_length_n + 1);
if (buf != NULL) {
buf->memory = 1;
buf->temporary = 0;
ngx_memset(buf->start, '\0', r->headers_in.content_length_n + 1);
chain = r->request_body->bufs;
......
......@@ -362,7 +362,7 @@ ngx_http_push_stream_postconfig(ngx_conf_t *cf)
{
if ((ngx_http_push_stream_padding_max_len > 0) && (ngx_http_push_stream_module_paddings_chunks == NULL)) {
ngx_uint_t steps = ngx_http_push_stream_padding_max_len / 100;
if ((ngx_http_push_stream_module_paddings_chunks = ngx_palloc(cf->pool, sizeof(ngx_str_t) * (steps + 1))) == NULL) {
if ((ngx_http_push_stream_module_paddings_chunks = ngx_pcalloc(cf->pool, sizeof(ngx_str_t) * (steps + 1))) == NULL) {
ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "push stream module: unable to allocate memory to create padding messages");
return NGX_ERROR;
}
......@@ -394,7 +394,7 @@ ngx_http_push_stream_postconfig(ngx_conf_t *cf)
if ((ngx_http_push_stream_padding_max_len > 0) && (ngx_http_push_stream_module_paddings_chunks_for_eventsource == NULL)) {
ngx_uint_t steps = ngx_http_push_stream_padding_max_len / 100;
if ((ngx_http_push_stream_module_paddings_chunks_for_eventsource = ngx_palloc(cf->pool, sizeof(ngx_str_t) * (steps + 1))) == NULL) {
if ((ngx_http_push_stream_module_paddings_chunks_for_eventsource = ngx_pcalloc(cf->pool, sizeof(ngx_str_t) * (steps + 1))) == NULL) {
ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "push stream module: unable to allocate memory to create padding messages for eventsource");
return NGX_ERROR;
}
......
......@@ -602,7 +602,7 @@ ngx_http_push_stream_create_channel_subscription(ngx_http_request_t *r, ngx_http
{
ngx_http_push_stream_subscription_t *subscription;
if ((subscription = ngx_palloc(r->pool, sizeof(ngx_http_push_stream_subscription_t))) == NULL) {
if ((subscription = ngx_pcalloc(r->pool, sizeof(ngx_http_push_stream_subscription_t))) == NULL) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "push stream module: unable to allocate subscribed channel reference");
return NULL;
}
......
......@@ -315,7 +315,7 @@ ngx_http_push_stream_convert_char_to_msg_on_shared(ngx_http_push_stream_main_con
return NULL;
}
for (q_line = ngx_queue_head(lines); q_line != ngx_queue_sentinel(lines); q_line = ngx_queue_next(q_line )) {
for (q_line = ngx_queue_head(lines); q_line != ngx_queue_sentinel(lines); q_line = ngx_queue_next(q_line )) {
cur_line = ngx_queue_data(q_line , ngx_http_push_stream_line_t, queue);
if ((cur_line->line = ngx_http_push_stream_format_message(channel, msg, cur_line->line, cur, temp_pool)) == NULL) {
break;
......@@ -748,6 +748,7 @@ ngx_http_push_stream_send_response_text(ngx_http_request_t *r, const u_char *tex
b->last_in_chain = 1;
b->flush = 1;
b->memory = 1;
b->temporary = 0;
b->pos = (u_char *) text;
b->start = b->pos;
b->end = b->pos + len;
......@@ -1177,7 +1178,7 @@ ngx_http_push_stream_timer_set(ngx_msec_t timer_interval, ngx_event_t *event, ng
static void
ngx_http_push_stream_timer_reset(ngx_msec_t timer_interval, ngx_event_t *timer_event)
{
if (!ngx_exiting && (timer_interval != NGX_CONF_UNSET_MSEC)) {
if (!ngx_exiting && (timer_interval != NGX_CONF_UNSET_MSEC) && (timer_event != NULL)) {
if (timer_event->timedout) {
ngx_time_update();
}
......@@ -1192,12 +1193,17 @@ ngx_http_push_stream_ping_timer_wake_handler(ngx_event_t *ev)
ngx_http_request_t *r = (ngx_http_request_t *) ev->data;
ngx_http_push_stream_main_conf_t *mcf = ngx_http_get_module_main_conf(r, ngx_http_push_stream_module);
ngx_http_push_stream_loc_conf_t *pslcf = ngx_http_get_module_loc_conf(r, ngx_http_push_stream_module);
ngx_http_push_stream_module_ctx_t *ctx = ngx_http_get_module_ctx(r, ngx_http_push_stream_module);
ngx_int_t rc = NGX_OK;
if ((ctx == NULL) || (ctx->ping_timer == NULL)) {
return;
}
if (pslcf->location_type == NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_EVENTSOURCE) {
rc = ngx_http_push_stream_send_response_text(r, NGX_HTTP_PUSH_STREAM_EVENTSOURCE_PING_MESSAGE_CHUNK.data, NGX_HTTP_PUSH_STREAM_EVENTSOURCE_PING_MESSAGE_CHUNK.len, 0);
} else if (pslcf->location_type == NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_WEBSOCKET) {
rc = ngx_http_push_stream_send_response_text(r, NGX_HTTP_PUSH_STREAM_WEBSOCKET_PING_LAST_FRAME_BYTE, sizeof(NGX_HTTP_PUSH_STREAM_WEBSOCKET_PING_LAST_FRAME_BYTE), 1);
rc = ngx_http_push_stream_send_response_text(r, NGX_HTTP_PUSH_STREAM_WEBSOCKET_PING_LAST_FRAME_BYTE, sizeof(NGX_HTTP_PUSH_STREAM_WEBSOCKET_PING_LAST_FRAME_BYTE), 0);
} else {
if (mcf->ping_msg == NULL) {
// create ping message
......@@ -1214,7 +1220,6 @@ ngx_http_push_stream_ping_timer_wake_handler(ngx_event_t *ev)
if (rc != NGX_OK) {
ngx_http_push_stream_send_response_finalize(r);
} else {
ngx_http_push_stream_module_ctx_t *ctx = ngx_http_get_module_ctx(r, ngx_http_push_stream_module);
ngx_http_push_stream_timer_reset(pslcf->ping_message_interval, ctx->ping_timer);
}
}
......@@ -1424,15 +1429,18 @@ ngx_http_push_stream_cleanup_request_context(ngx_http_request_t *r)
ngx_del_timer(ctx->ping_timer);
}
if (ctx->subscriber != NULL) {
ngx_http_push_stream_worker_subscriber_cleanup(ctx->subscriber);
}
if (ctx->temp_pool != NULL) {
ngx_destroy_pool(ctx->temp_pool);
ctx->temp_pool = NULL;
}
if (ctx->subscriber != NULL) {
ngx_http_push_stream_worker_subscriber_cleanup(ctx->subscriber);
ctx->subscriber = NULL;
}
ctx->temp_pool = NULL;
ctx->disconnect_timer = NULL;
ctx->ping_timer = NULL;
ctx->subscriber = NULL;
}
}
......@@ -1900,6 +1908,8 @@ ngx_http_push_stream_send_only_added_headers(ngx_http_request_t *r)
out.buf = b;
out.next = NULL;
b->flush = 1;
b->memory = 1;
b->temporary = 0;
return ngx_http_write_filter(r, &out);
}
......@@ -1917,7 +1927,7 @@ ngx_http_push_stream_parse_paddings(ngx_conf_t *cf, ngx_str_t *paddings_by_user
ngx_str_t aux, *agent;
if ((paddings = ngx_palloc(cf->pool, sizeof(ngx_queue_t))) == NULL) {
if ((paddings = ngx_pcalloc(cf->pool, sizeof(ngx_queue_t))) == NULL) {
ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "push stream module: unable to allocate memory to save padding info");
return NULL;
}
......@@ -1976,7 +1986,7 @@ ngx_http_push_stream_parse_paddings(ngx_conf_t *cf, ngx_str_t *paddings_by_user
return NULL;
}
if ((padding = ngx_palloc(cf->pool, sizeof(ngx_http_push_stream_padding_t))) == NULL) {
if ((padding = ngx_pcalloc(cf->pool, sizeof(ngx_http_push_stream_padding_t))) == NULL) {
ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "push stream module: unable to allocate memory to save padding info");
return NULL;
}
......
......@@ -377,5 +377,6 @@ ngx_http_push_stream_set_buffer(ngx_buf_t *buf, u_char *start, u_char *last, ssi
buf->pos = buf->start;
buf->last = (last != NULL) ? last : start;
buf->end = buf->start + len;
buf->temporary = 1;
buf->temporary = 0;
buf->memory = 1;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment