diff options
Diffstat (limited to 'res/res_pjsip_registrar_expire.c')
-rw-r--r-- | res/res_pjsip_registrar_expire.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/res/res_pjsip_registrar_expire.c b/res/res_pjsip_registrar_expire.c index e52363e13..0d979a13f 100644 --- a/res/res_pjsip_registrar_expire.c +++ b/res/res_pjsip_registrar_expire.c @@ -30,6 +30,7 @@ #include "asterisk/res_pjsip.h" #include "asterisk/module.h" +#include "asterisk/named_locks.h" /*! \brief Thread keeping things alive */ static pthread_t check_thread = AST_PTHREADT_NULL; @@ -41,8 +42,23 @@ static unsigned int check_interval; static int expire_contact(void *obj, void *arg, int flags) { struct ast_sip_contact *contact = obj; + struct ast_named_lock *lock; - ast_sorcery_delete(ast_sip_get_sorcery(), contact); + lock = ast_named_lock_get(AST_NAMED_LOCK_TYPE_RWLOCK, "aor", contact->aor); + if (!lock) { + return 0; + } + + /* + * We need to check the expiration again with the aor lock held + * in case another thread is attempting to renew the contact. + */ + ao2_wrlock(lock); + if (ast_tvdiff_ms(ast_tvnow(), contact->expiration_time) > 0) { + ast_sip_location_delete_contact(contact); + } + ao2_unlock(lock); + ast_named_lock_put(lock); return 0; } |