Skip to content

Commit cf2904c

Browse files
author
Mikhail Kirichenko
committed
RB-41043: remove uninitialized metric, gauge or statistic from storage if no memory left
1 parent f89d035 commit cf2904c

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

src/ngx_http_graphite_module.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,7 @@ ngx_http_graphite_add_param_to_data(ngx_http_graphite_context_t *context, ngx_ui
10391039
if (context->phase == PHASE_REQUEST) {
10401040
metric->data = ngx_http_graphite_allocator_alloc(storage->allocator, sizeof(ngx_http_graphite_metric_data_t) * (storage->max_interval + 1));
10411041
if (metric->data == NULL) {
1042+
storage->metrics->nelts--;
10421043
ngx_log_error(NGX_LOG_ERR, context->log, 0, "graphite can't alloc memory");
10431044
return NGX_CONF_ERROR;
10441045
}
@@ -1076,6 +1077,7 @@ ngx_http_graphite_add_param_to_data(ngx_http_graphite_context_t *context, ngx_ui
10761077
if (context->phase == PHASE_REQUEST) {
10771078
gauge->data = ngx_http_graphite_allocator_alloc(storage->allocator, sizeof(ngx_http_graphite_gauge_data_t));
10781079
if (gauge->data == NULL) {
1080+
storage->gauges->nelts--;
10791081
ngx_log_error(NGX_LOG_ERR, context->log, 0, "graphite can't alloc memory");
10801082
return NGX_CONF_ERROR;
10811083
}
@@ -1113,6 +1115,7 @@ ngx_http_graphite_add_param_to_data(ngx_http_graphite_context_t *context, ngx_ui
11131115
if (context->phase == PHASE_REQUEST) {
11141116
statistic->data = ngx_http_graphite_allocator_alloc(storage->allocator, sizeof(ngx_http_graphite_statistic_data_t));
11151117
if (statistic->data == NULL) {
1118+
storage->statistics->nelts--;
11161119
ngx_log_error(NGX_LOG_ERR, context->log, 0, "graphite can't alloc memory");
11171120
return NGX_CONF_ERROR;
11181121
}

0 commit comments

Comments
 (0)