Skip to content

Commit

Permalink
Bugfix: fixed issues/248 Shared memory (lock|unlock) is set when usin…
Browse files Browse the repository at this point in the history
…g the ngx_http_vhost_traffic_status_display_get_size() function
  • Loading branch information
vozlt committed Sep 26, 2022
1 parent f731137 commit 1277c01
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/ngx_http_vhost_traffic_status_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,15 +524,25 @@ ngx_http_vhost_traffic_status_display_get_size(ngx_http_request_t *r,
ngx_int_t format)
{
ngx_uint_t size, un;
ngx_slab_pool_t *shpool;
ngx_http_vhost_traffic_status_loc_conf_t *vtscf;
ngx_http_vhost_traffic_status_shm_info_t *shm_info;

vtscf = ngx_http_get_module_loc_conf(r, ngx_http_vhost_traffic_status_module);
shpool = (ngx_slab_pool_t *) vtscf->shm_zone->shm.addr;

shm_info = ngx_pcalloc(r->pool, sizeof(ngx_http_vhost_traffic_status_shm_info_t));
if (shm_info == NULL) {
return NGX_ERROR;
}

/* Caveat: Do not use duplicate ngx_shmtx_lock() before this function. */
ngx_shmtx_lock(&shpool->mutex);

ngx_http_vhost_traffic_status_shm_info(r, shm_info);

ngx_shmtx_unlock(&shpool->mutex);

/* allocate memory for the upstream groups even if upstream node not exists */
un = shm_info->used_node
+ (ngx_uint_t) ngx_http_vhost_traffic_status_display_get_upstream_nelts(r);
Expand Down

0 comments on commit 1277c01

Please sign in to comment.