From 623840e7487cec1862531893c3644776835d9387 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Fri, 28 Apr 2017 09:35:41 +0200 Subject: [PATCH] db_cluster: free allocated structure at init time - avoid reopening driver db connections if already set (cherry picked from commit 08f8e0bc72b9f16f76b78110c9c95b1ba7f1ce25) --- src/modules/db_cluster/dbcl_api.c | 10 ++++++---- src/modules/db_cluster/dbcl_data.c | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/modules/db_cluster/dbcl_api.c b/src/modules/db_cluster/dbcl_api.c index 1f24cc547d9..6ef6ec4db03 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 534030ccd41..47f9444d190 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; jrlist[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; jwlist[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,