Skip to content

Commit 1277c01

Browse files
committed
Bugfix: fixed issues/248 Shared memory (lock|unlock) is set when using the ngx_http_vhost_traffic_status_display_get_size() function
1 parent f731137 commit 1277c01

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/ngx_http_vhost_traffic_status_display.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,15 +524,25 @@ ngx_http_vhost_traffic_status_display_get_size(ngx_http_request_t *r,
524524
ngx_int_t format)
525525
{
526526
ngx_uint_t size, un;
527+
ngx_slab_pool_t *shpool;
528+
ngx_http_vhost_traffic_status_loc_conf_t *vtscf;
527529
ngx_http_vhost_traffic_status_shm_info_t *shm_info;
528530

531+
vtscf = ngx_http_get_module_loc_conf(r, ngx_http_vhost_traffic_status_module);
532+
shpool = (ngx_slab_pool_t *) vtscf->shm_zone->shm.addr;
533+
529534
shm_info = ngx_pcalloc(r->pool, sizeof(ngx_http_vhost_traffic_status_shm_info_t));
530535
if (shm_info == NULL) {
531536
return NGX_ERROR;
532537
}
533538

539+
/* Caveat: Do not use duplicate ngx_shmtx_lock() before this function. */
540+
ngx_shmtx_lock(&shpool->mutex);
541+
534542
ngx_http_vhost_traffic_status_shm_info(r, shm_info);
535543

544+
ngx_shmtx_unlock(&shpool->mutex);
545+
536546
/* allocate memory for the upstream groups even if upstream node not exists */
537547
un = shm_info->used_node
538548
+ (ngx_uint_t) ngx_http_vhost_traffic_status_display_get_upstream_nelts(r);

0 commit comments

Comments
 (0)