mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-30 02:26:23 +00:00
Merge "Fix creation race of contact_status structures."
This commit is contained in:
@@ -107,6 +107,8 @@ static void *contact_status_alloc(const char *name)
|
||||
return status;
|
||||
}
|
||||
|
||||
AST_MUTEX_DEFINE_STATIC(creation_lock);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve a ast_sip_contact_status object from sorcery creating
|
||||
* one if not found.
|
||||
@@ -114,6 +116,7 @@ static void *contact_status_alloc(const char *name)
|
||||
struct ast_sip_contact_status *ast_res_pjsip_find_or_create_contact_status(const struct ast_sip_contact *contact)
|
||||
{
|
||||
struct ast_sip_contact_status *status;
|
||||
SCOPED_MUTEX(lock, &creation_lock);
|
||||
|
||||
status = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), CONTACT_STATUS,
|
||||
ast_sorcery_object_get_id(contact));
|
||||
|
@@ -98,7 +98,21 @@ static int sorcery_memory_cmp(void *obj, void *arg, int flags)
|
||||
|
||||
static int sorcery_memory_create(const struct ast_sorcery *sorcery, void *data, void *object)
|
||||
{
|
||||
ao2_link(data, object);
|
||||
void *existing;
|
||||
|
||||
ao2_lock(data);
|
||||
|
||||
existing = ao2_find(data, ast_sorcery_object_get_id(object), OBJ_KEY | OBJ_NOLOCK);
|
||||
if (existing) {
|
||||
ao2_ref(existing, -1);
|
||||
ao2_unlock(data);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ao2_link_flags(data, object, OBJ_NOLOCK);
|
||||
|
||||
ao2_unlock(data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user