Skip to content

Commit

Permalink
htable: do not call expired event route on get/add operations
Browse files Browse the repository at this point in the history
- 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

(cherry picked from commit 4514c91)
  • Loading branch information
miconda committed Jun 26, 2017
1 parent c71bac4 commit 8038327
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
22 changes: 1 addition & 21 deletions src/modules/htable/ht_api.c
Expand Up @@ -676,24 +676,14 @@ 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 */
it->flags &= ~AVP_VAL_STR;
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;
}
}
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions src/modules/htable/ht_var.c
Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 8038327

Please sign in to comment.