struct ast_bt *__ast_bt_create(void) { struct ast_bt *bt = ast_std_calloc(1, sizeof(*bt)); if (!bt) { return NULL; } bt->alloced = 1; ast_bt_get_addresses(bt); return bt; }
/*! * \brief Create an \ref optional_api. * * \param symname Name of the optional function. * \return New \ref optional_api. * \return \c NULL on error. */ static struct optional_api *optional_api_create(const char *symname) { struct optional_api *api; size_t size; size = sizeof(*api) + strlen(symname) + 1; api = ast_std_calloc(1, size); if (!api) { ast_log(LOG_ERROR, "Failed to allocate api\n"); return NULL; } strcpy(api->symname, symname); /* SAFE */ return api; }
/*! * \brief Create an \ref optional_api_user. * * \param optional_ref Pointer-to-function-pointer to link to impl/stub. * \param stub Stub function to link to when impl is not available. * \param module Name of the module requesting the API. * * \return New \ref optional_api_user. * \return \c NULL on error. */ static struct optional_api_user *optional_api_user_create( ast_optional_fn *optional_ref, ast_optional_fn stub, const char *module) { struct optional_api_user *user; size_t size = sizeof(*user) + strlen(module) + 1; user = ast_std_calloc(1, size); if (!user) { return NULL; } user->optional_ref = optional_ref; user->stub = stub; strcpy(user->module, module); /* SAFE */ return user; }
static inline struct ast_lock_track *ast_get_reentrancy(struct ast_lock_track **plt) { pthread_mutexattr_t reentr_attr; struct ast_lock_track *lt; /* It's a bit painful to lock a global mutex for every access to the * reentrancy structure, but it's necessary to ensure that we don't * double-allocate the structure or double-initialize the reentr_mutex. * * If you'd like to replace this with a double-checked lock, be sure to * properly volatile-ize everything to avoid optimizer bugs. * * We also have to use the underlying pthread calls for manipulating * the mutex, because this is called from the Asterisk mutex code. */ pthread_mutex_lock(&reentrancy_lock.mutex); if (*plt) { pthread_mutex_unlock(&reentrancy_lock.mutex); return *plt; } lt = *plt = ast_std_calloc(1, sizeof(*lt)); if (!lt) { fprintf(stderr, "%s: Failed to allocate lock tracking\n", __func__); #if defined(DO_CRASH) || defined(THREAD_CRASH) abort(); #else pthread_mutex_unlock(&reentrancy_lock.mutex); return NULL; #endif } pthread_mutexattr_init(&reentr_attr); pthread_mutexattr_settype(&reentr_attr, AST_MUTEX_KIND); pthread_mutex_init(<->reentr_mutex, &reentr_attr); pthread_mutexattr_destroy(&reentr_attr); pthread_mutex_unlock(&reentrancy_lock.mutex); return lt; }