Skip to content

Commit

Permalink
possible SIGSEGV on reload
Browse files Browse the repository at this point in the history
  • Loading branch information
ZigzagAK committed May 28, 2018
1 parent 1ce0b66 commit 9dba558
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/ngx_dynamic_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ ngx_shm_copy_pairs(ngx_slab_pool_t *shpool, ngx_pair_t *src, ngx_uint_t count)
ngx_pair_t *pairs = NULL;
ngx_uint_t i;
if (count) {
pairs = ngx_slab_calloc(shpool, count * sizeof(ngx_pair_t));
pairs = ngx_slab_calloc_locked(shpool, count * sizeof(ngx_pair_t));
if (pairs != NULL) {
for (i = 0; i < count; ++i) {
pairs[i].name = ngx_shm_copy_string(shpool, src[i].name);
Expand All @@ -110,7 +110,7 @@ ngx_shm_copy_uint_vec(ngx_slab_pool_t *shpool, ngx_uint_t *src, ngx_uint_t count
{
ngx_uint_t *codes = NULL;
if (count) {
codes = ngx_slab_calloc(shpool, count * sizeof(ngx_uint_t));
codes = ngx_slab_calloc_locked(shpool, count * sizeof(ngx_uint_t));
if (codes != NULL) {
ngx_memcpy(codes, src, count * sizeof(ngx_uint_t));
}
Expand Down
9 changes: 7 additions & 2 deletions src/ngx_dynamic_upstream_lua_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,11 @@ ngx_http_init_shm_zone(ngx_shm_zone_t *shm_zone, void *data)
return NGX_OK;
}

ucscf->data = ngx_slab_calloc(ucscf->shpool, sizeof(ngx_http_upstream_check_opts_t));
ngx_shmtx_lock(&ucscf->shpool->mutex);

ucscf->data = ngx_slab_calloc_locked(ucscf->shpool, sizeof(ngx_http_upstream_check_opts_t));
if (ucscf->data == NULL) {
ngx_shmtx_unlock(&ucscf->shpool->mutex);
return NGX_ERROR;
}

Expand Down Expand Up @@ -233,6 +236,8 @@ ngx_http_init_shm_zone(ngx_shm_zone_t *shm_zone, void *data)
rc = rc && (ucscf->data->request_headers || NULL == ucscf->conf->request_headers);
rc = rc && (ucscf->data->response_codes || NULL == ucscf->conf->response_codes);

ngx_shmtx_unlock(&ucscf->shpool->mutex);

if (!rc) {
return NGX_ERROR;
}
Expand Down Expand Up @@ -473,7 +478,7 @@ ngx_http_dynamic_upstream_lua_check_response_codes(ngx_conf_t *cf, ngx_command_t
if (ucscf == NULL) {
return NGX_CONF_ERROR;
}

value = cf->args->elts;

ucscf->conf->response_codes_count = cf->args->nelts - 1;
Expand Down
10 changes: 7 additions & 3 deletions src/ngx_dynamic_upstream_stream_lua_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ ngx_stream_dynamic_upstream_write_filter(ngx_stream_session_t *s, ngx_chain_t *i
}

if (uscf->srv_conf == NULL) {
goto skip;
goto skip;
}

ucscf = ngx_stream_conf_upstream_srv_conf(uscf, ngx_stream_dynamic_upstream_lua_module);
Expand Down Expand Up @@ -303,8 +303,11 @@ ngx_stream_init_shm_zone(ngx_shm_zone_t *shm_zone, void *data)
return NGX_OK;
}

ucscf->data = ngx_slab_calloc(ucscf->shpool, sizeof(ngx_stream_upstream_check_opts_t));
ngx_shmtx_lock(&ucscf->shpool->mutex);

ucscf->data = ngx_slab_calloc_locked(ucscf->shpool, sizeof(ngx_stream_upstream_check_opts_t));
if (ucscf->data == NULL) {
ngx_shmtx_unlock(&ucscf->shpool->mutex);
return NGX_ERROR;
}

Expand All @@ -316,11 +319,12 @@ ngx_stream_init_shm_zone(ngx_shm_zone_t *shm_zone, void *data)
ucscf->data->request_body = ngx_shm_copy_string(ucscf->shpool, ucscf->conf->request_body);
ucscf->data->response_body = ngx_shm_copy_string(ucscf->shpool, ucscf->conf->response_body);


rc = rc && (ucscf->data->upstream.data || NULL == ucscf->conf->upstream.data);
rc = rc && (ucscf->data->request_body.data || NULL == ucscf->conf->request_body.data);
rc = rc && (ucscf->data->response_body.data || NULL == ucscf->conf->response_body.data);

ngx_shmtx_unlock(&ucscf->shpool->mutex);

if (!rc) {
return NGX_ERROR;
}
Expand Down

0 comments on commit 9dba558

Please sign in to comment.