Module: kamailio Branch: 5.0 Commit: 623840e7487cec1862531893c3644776835d9387 URL: https://github.com/kamailio/kamailio/commit/623840e7487cec1862531893c3644776...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2017-05-03T08:59:35+02:00
db_cluster: free allocated structure at init time
- avoid reopening driver db connections if already set
(cherry picked from commit 08f8e0bc72b9f16f76b78110c9c95b1ba7f1ce25)
---
Modified: src/modules/db_cluster/dbcl_api.c Modified: src/modules/db_cluster/dbcl_data.c
---
Diff: https://github.com/kamailio/kamailio/commit/623840e7487cec1862531893c3644776... Patch: https://github.com/kamailio/kamailio/commit/623840e7487cec1862531893c3644776...
---
diff --git a/src/modules/db_cluster/dbcl_api.c b/src/modules/db_cluster/dbcl_api.c index 1f24cc5..6ef6ec4 100644 --- a/src/modules/db_cluster/dbcl_api.c +++ b/src/modules/db_cluster/dbcl_api.c @@ -311,10 +311,12 @@ void db_cluster_close(db1_con_t* _h) LM_DBG("executing db cluster close command\n"); cls = (dbcl_cls_t*)_h->tail; cls->ref--; - if(cls->ref > 0) - return; - /* close connections */ - dbcl_close_connections(cls); + if(cls->ref <= 0) { + /* close connections */ + dbcl_close_connections(cls); + } + /* free _h - allocated for each db_cluster_init() */ + pkg_free(_h); return; }
diff --git a/src/modules/db_cluster/dbcl_data.c b/src/modules/db_cluster/dbcl_data.c index 534030c..47f9444 100644 --- a/src/modules/db_cluster/dbcl_data.c +++ b/src/modules/db_cluster/dbcl_data.c @@ -442,7 +442,8 @@ int dbcl_init_connections(dbcl_cls_t *cls) { for(j=0; j<cls->rlist[i].clen; j++) { - if(cls->rlist[i].clist[j] != NULL && cls->rlist[i].clist[j]->flags!=0) + if(cls->rlist[i].clist[j] != NULL && cls->rlist[i].clist[j]->flags!=0 + && cls->rlist[i].clist[j]->dbh==NULL) { LM_DBG("setting up read connection [%.*s]\n", cls->rlist[i].clist[j]->name.len, @@ -459,7 +460,8 @@ int dbcl_init_connections(dbcl_cls_t *cls) } for(j=0; j<cls->wlist[i].clen; j++) { - if(cls->wlist[i].clist[j] != NULL && cls->wlist[i].clist[j]->flags!=0) + if(cls->wlist[i].clist[j] != NULL && cls->wlist[i].clist[j]->flags!=0 + && cls->wlist[i].clist[j]->dbh==NULL) { LM_DBG("setting up write connection [%.*s]\n", cls->wlist[i].clist[j]->name.len,