struct ast_datastore *__ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid, const char *file, int line, const char *function) { struct ast_datastore *datastore = NULL; /* Make sure we at least have type so we can identify this */ if (!info) { return NULL; } #if defined(__AST_DEBUG_MALLOC) if (!(datastore = __ast_calloc(1, sizeof(*datastore), file, line, function))) { return NULL; } #else if (!(datastore = ast_calloc(1, sizeof(*datastore)))) { return NULL; } #endif datastore->info = info; if (!ast_strlen_zero(uid) && !(datastore->uid = ast_strdup(uid))) { ast_free(datastore); datastore = NULL; } return datastore; }
struct ast_datastore *__ast_datastore_alloc( const struct ast_datastore_info *info, const char *uid, struct ast_module *mod, const char *file, int line, const char *function) { struct ast_datastore *datastore = NULL; /* Make sure we at least have type so we can identify this */ if (!info) { return NULL; } datastore = __ast_calloc(1, sizeof(*datastore), file, line, function); if (!datastore) { return NULL; } datastore->info = info; datastore->mod = mod; if (!ast_strlen_zero(uid) && !(datastore->uid = ast_strdup(uid))) { ast_free(datastore); datastore = NULL; } ast_module_ref(mod); return datastore; }
struct ast_var_t *ast_var_assign(const char *name, const char *value) #endif { struct ast_var_t *var; int name_len = strlen(name) + 1; int value_len = strlen(value) + 1; #ifdef MALLOC_DEBUG if (!(var = __ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char), file, lineno, function))) { #else if (!(var = ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char)))) { #endif return NULL; } ast_copy_string(var->name, name, name_len); var->value = var->name + name_len; ast_copy_string(var->value, value, value_len); return var; } void ast_var_delete(struct ast_var_t *var) { ast_free(var); }
static void *calloc_wrapper(unsigned int num_structs, size_t struct_size, const char *file, int lineno, const char *func) { #if defined(__AST_DEBUG_MALLOC) return __ast_calloc(num_structs, struct_size, file, lineno, func); #else return ast_calloc(num_structs, struct_size); #endif }
struct ast_heap *ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_fn, ssize_t index_offset) #endif { struct ast_heap *h; if (!cmp_fn) { ast_log(LOG_ERROR, "A comparison function must be provided\n"); return NULL; } if (!init_height) { init_height = 8; } if (!(h = #ifdef MALLOC_DEBUG __ast_calloc(1, sizeof(*h), file, lineno, func) #else ast_calloc(1, sizeof(*h)) #endif )) { return NULL; } h->cmp_fn = cmp_fn; h->index_offset = index_offset; h->avail_len = (1 << init_height) - 1; if (!(h->heap = #ifdef MALLOC_DEBUG __ast_calloc(1, h->avail_len * sizeof(void *), file, lineno, func) #else ast_calloc(1, h->avail_len * sizeof(void *)) #endif )) { ast_free(h); return NULL; } ast_rwlock_init(&h->lock); return h; }
struct ast_var_t *_ast_var_assign(const char *name, const char *value, const char *file, int lineno, const char *function) { struct ast_var_t *var; int name_len = strlen(name) + 1; int value_len = strlen(value) + 1; var = __ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char), file, lineno, function); if (!var) { return NULL; } ast_copy_string(var->name, name, name_len); var->value = var->name + name_len; ast_copy_string(var->value, value, value_len); return var; }
static void *internal_ao2_alloc(size_t data_size, ao2_destructor_fn destructor_fn, unsigned int options, const char *file, int line, const char *func) { /* allocation */ struct astobj2 *obj; struct astobj2_lock *obj_mutex; struct astobj2_rwlock *obj_rwlock; switch (options & AO2_ALLOC_OPT_LOCK_MASK) { case AO2_ALLOC_OPT_LOCK_MUTEX: #if defined(__AST_DEBUG_MALLOC) obj_mutex = __ast_calloc(1, sizeof(*obj_mutex) + data_size, file, line, func); #else obj_mutex = ast_calloc(1, sizeof(*obj_mutex) + data_size); #endif if (obj_mutex == NULL) { return NULL; } ast_mutex_init(&obj_mutex->mutex.lock); obj = (struct astobj2 *) &obj_mutex->priv_data; break; case AO2_ALLOC_OPT_LOCK_RWLOCK: #if defined(__AST_DEBUG_MALLOC) obj_rwlock = __ast_calloc(1, sizeof(*obj_rwlock) + data_size, file, line, func); #else obj_rwlock = ast_calloc(1, sizeof(*obj_rwlock) + data_size); #endif if (obj_rwlock == NULL) { return NULL; } ast_rwlock_init(&obj_rwlock->rwlock.lock); obj = (struct astobj2 *) &obj_rwlock->priv_data; break; case AO2_ALLOC_OPT_LOCK_NOLOCK: #if defined(__AST_DEBUG_MALLOC) obj = __ast_calloc(1, sizeof(*obj) + data_size, file, line, func); #else obj = ast_calloc(1, sizeof(*obj) + data_size); #endif if (obj == NULL) { return NULL; } break; default: /* Invalid option value. */ ast_log(__LOG_DEBUG, file, line, func, "Invalid lock option requested\n"); return NULL; } /* Initialize common ao2 values. */ obj->priv_data.ref_counter = 1; obj->priv_data.destructor_fn = destructor_fn; /* can be NULL */ obj->priv_data.data_size = data_size; obj->priv_data.options = options; obj->priv_data.magic = AO2_MAGIC; #ifdef AO2_DEBUG ast_atomic_fetchadd_int(&ao2.total_objects, 1); ast_atomic_fetchadd_int(&ao2.total_mem, data_size); ast_atomic_fetchadd_int(&ao2.total_refs, 1); #endif /* return a pointer to the user data */ return EXTERNAL_OBJ(obj); }