Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion ngx_http_mysql_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ static char* ngx_http_mysql_query(ngx_conf_t *cf, ngx_command_t *cmd, void *conf
static char* ngx_http_mysql_subrequest(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char* ngx_http_mysql_escape(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);

static void ngx_http_mysql_cleanup(void *data);

static ngx_int_t ngx_http_mysql_init(ngx_conf_t *cf);

struct ngx_http_mysql_loc_conf_s {
Expand Down Expand Up @@ -660,6 +662,7 @@ static char* ngx_http_mysql_merge_srv_conf(ngx_conf_t *cf, void *parent, void *c
{
ngx_http_mysql_srv_conf_t *prev = parent;
ngx_http_mysql_srv_conf_t *conf = child;
ngx_pool_cleanup_t *cp;
ngx_int_t n;

ngx_log_debug0(NGX_LOG_INFO, cf->log, 0, "mysql merge srv");
Expand Down Expand Up @@ -687,9 +690,15 @@ static char* ngx_http_mysql_merge_srv_conf(ngx_conf_t *cf, void *parent, void *c

conf->free_node = conf->nodes;

for(n = 0; n < conf->max_conn - 1; ++n)
for (n = 0; n < conf->max_conn - 1; ++n)
conf->nodes[n].next = conf->nodes + n + 1;

cp = ngx_pool_cleanup_add(cf->pool, 0);
if (cp == NULL) {
return NGX_CONF_ERROR;
}
cp->handler = ngx_http_mysql_cleanup;
cp->data = conf->nodes;
} else if (prev->max_conn != NGX_CONF_UNSET) {

conf->max_conn = prev->max_conn;
Expand Down Expand Up @@ -850,6 +859,18 @@ static char* ngx_http_mysql_escape(ngx_conf_t *cf, ngx_command_t *cmd, void *con
return NGX_CONF_OK;
}

static void ngx_http_mysql_cleanup(void *data)
{
ngx_http_mysql_node_t *p, *nodes;

nodes = (ngx_http_mysql_node_t *)data;
for (p = nodes; p; p = p->next) {
if (p->ready) {
mysql_close(&p->mysql);
}
}
}

static ngx_int_t ngx_http_mysql_init(ngx_conf_t *cf)
{
ngx_http_core_main_conf_t *cmcf;
Expand Down