[sr-dev] git:master:4514c918: htable: do not call expired event route on get/add operations

Daniel-Constantin Mierla miconda at gmail.com
Fri Jun 23 18:29:17 CEST 2017


Module: kamailio
Branch: master
Commit: 4514c91883d67ee062582aed7b414633609cf6ac
URL: https://github.com/kamailio/kamailio/commit/4514c91883d67ee062582aed7b414633609cf6ac

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-06-23T18:25:32+02:00

htable: do not call expired event route on get/add operations

- have consistent behaviour with set operation
- avoid accessing the same (expired) item twice, second after being
  removed if the item is accessed in the event route
- reported by GH #1152

---

Modified: src/modules/htable/ht_api.c
Modified: src/modules/htable/ht_var.c

---

Diff:  https://github.com/kamailio/kamailio/commit/4514c91883d67ee062582aed7b414633609cf6ac.diff
Patch: https://github.com/kamailio/kamailio/commit/4514c91883d67ee062582aed7b414633609cf6ac.patch

---

diff --git a/src/modules/htable/ht_api.c b/src/modules/htable/ht_api.c
index 1bbd079b30..03aee19a72 100644
--- a/src/modules/htable/ht_api.c
+++ b/src/modules/htable/ht_api.c
@@ -676,7 +676,6 @@ ht_cell_t* ht_cell_value_add(ht_t *ht, str *name, int val, int mode,
 			/* found */
 			if(now>0 && it->expire!=0 && it->expire<now) {
 				/* entry has expired */
-				ht_handle_expired_record(ht, it);
 
 				if(ht->flags==PV_VAL_INT) {
 					/* initval is integer, use it to create a fresh entry */
@@ -684,16 +683,7 @@ ht_cell_t* ht_cell_value_add(ht_t *ht, str *name, int val, int mode,
 					it->value.n = ht->initval.n;
 					/* increment will be done below */
 				} else {
-					/* delete expired entry */
-					if(it->prev==NULL)
-						ht->entries[idx].first = it->next;
-					else
-						it->prev->next = it->next;
-					if(it->next)
-						it->next->prev = it->prev;
-					ht->entries[idx].esize--;
 					if(mode) ht_slot_unlock(ht, idx);
-					ht_cell_free(it);
 					return NULL;
 				}
 			}
@@ -804,18 +794,8 @@ ht_cell_t* ht_cell_pkg_copy(ht_t *ht, str *name, ht_cell_t *old)
 		{
 			/* found */
 			if(ht->htexpire>0 && it->expire!=0 && it->expire<time(NULL)) {
-				/* entry has expired, delete it and return NULL */
-				ht_handle_expired_record(ht, it);
-
-				if(it->prev==NULL)
-					ht->entries[idx].first = it->next;
-				else
-					it->prev->next = it->next;
-				if(it->next)
-					it->next->prev = it->prev;
-				ht->entries[idx].esize--;
+				/* entry has expired, return NULL */
 				ht_slot_unlock(ht, idx);
-				ht_cell_free(it);
 				return NULL;
 			}
 			if(old!=NULL)
diff --git a/src/modules/htable/ht_var.c b/src/modules/htable/ht_var.c
index 522811da58..c928bf1b49 100644
--- a/src/modules/htable/ht_var.c
+++ b/src/modules/htable/ht_var.c
@@ -91,7 +91,9 @@ int pv_set_ht_cell(struct sip_msg* msg, pv_param_t *param,
 	if((val==NULL) || (val->flags&PV_VAL_NULL))
 	{
 		/* delete it */
-		if (hpv->ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_DEL_CELL, &hpv->htname, &htname, 0, NULL, 0)!=0) {
+		if (hpv->ht->dmqreplicate>0
+				&& ht_dmq_replicate_action(HT_DMQ_DEL_CELL, &hpv->htname,
+					&htname, 0, NULL, 0)!=0) {
 			LM_ERR("dmq relication failed\n");
 		}
 		ht_del_cell(hpv->ht, &htname);
@@ -101,7 +103,9 @@ int pv_set_ht_cell(struct sip_msg* msg, pv_param_t *param,
 	if(val->flags&PV_TYPE_INT)
 	{
 		isval.n = val->ri;
-		if (hpv->ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL, &hpv->htname, &htname, 0, &isval, 1)!=0) {
+		if (hpv->ht->dmqreplicate>0
+				&& ht_dmq_replicate_action(HT_DMQ_SET_CELL, &hpv->htname,
+					&htname, 0, &isval, 1)!=0) {
 			LM_ERR("dmq relication failed\n");
 		}
 		if(ht_set_cell(hpv->ht, &htname, 0, &isval, 1)!=0)
@@ -111,7 +115,9 @@ int pv_set_ht_cell(struct sip_msg* msg, pv_param_t *param,
 		}
 	} else {
 		isval.s = val->rs;
-		if (hpv->ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL, &hpv->htname, &htname, AVP_VAL_STR, &isval, 1)!=0) {
+		if (hpv->ht->dmqreplicate>0
+				&& ht_dmq_replicate_action(HT_DMQ_SET_CELL, &hpv->htname,
+					&htname, AVP_VAL_STR, &isval, 1)!=0) {
 			LM_ERR("dmq relication failed\n");
 		}
 		if(ht_set_cell(hpv->ht, &htname, AVP_VAL_STR, &isval, 1)!=0)




More information about the sr-dev mailing list