summaryrefslogtreecommitdiff
path: root/main/optional_api.c
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2013-09-19 23:20:43 +0000
committerRichard Mudgett <rmudgett@digium.com>2013-09-19 23:20:43 +0000
commitcf9272c05c36a9e13b67c596fa5bc9df16de0c1b (patch)
treee922ef71b97e6d45f56a2480706ee5efcfb40035 /main/optional_api.c
parente89e19c479b8a44b45a48493b41f86f29f769f44 (diff)
optional_api: Make always use the standard malloc functions even with MALLOC_DEBUG.
........ Merged revisions 399501 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@399503 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/optional_api.c')
-rw-r--r--main/optional_api.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/main/optional_api.c b/main/optional_api.c
index 9c96fa646..f9d5fc68f 100644
--- a/main/optional_api.c
+++ b/main/optional_api.c
@@ -76,7 +76,7 @@ struct optional_api {
static void optional_api_user_destroy(struct optional_api_user *user)
{
*user->optional_ref = user->stub;
- free(user);
+ ast_std_free(user);
}
/*!
@@ -95,7 +95,7 @@ static struct optional_api_user *optional_api_user_create(
struct optional_api_user *user;
size_t size = sizeof(*user) + strlen(module) + 1;
- user = calloc(1, size);
+ user = ast_std_calloc(1, size);
if (!user) {
return NULL;
}
@@ -117,10 +117,10 @@ static void optional_api_destroy(struct optional_api *api)
while (api->users_len--) {
optional_api_user_destroy(api->users[api->users_len]);
}
- free(api->users);
+ ast_std_free(api->users);
api->users = NULL;
api->users_maxlen = 0;
- free(api);
+ ast_std_free(api);
}
/*!
@@ -137,7 +137,7 @@ static struct optional_api *optional_api_create(const char *symname)
ast_verb(6, "%s: building api object\n", symname);
size = sizeof(*api) + strlen(symname) + 1;
- api = calloc(1, size);
+ api = ast_std_calloc(1, size);
if (!api) {
ast_log(LOG_ERROR, "Failed to allocate api\n");
return NULL;
@@ -181,13 +181,16 @@ static struct optional_api *get_api(const char *symname)
/* API not found. Build one */
api = optional_api_create(symname);
+ if (!api) {
+ return NULL;
+ }
/* Grow the list, if needed */
if (apis.len + 1 > apis.maxlen) {
size_t new_maxlen = apis.maxlen ? 2 * apis.maxlen : 1;
- struct optional_api **new_list =
- realloc(apis.list, new_maxlen * sizeof(*new_list));
+ struct optional_api **new_list;
+ new_list = ast_std_realloc(apis.list, new_maxlen * sizeof(*new_list));
if (!new_list) {
optional_api_destroy(api);
ast_log(LOG_ERROR, "Failed to allocate api list\n");
@@ -300,11 +303,10 @@ void ast_optional_api_use(const char *symname, ast_optional_fn *optional_ref,
/* Add user to the API */
if (api->users_len + 1 > api->users_maxlen) {
- size_t new_maxlen = api->users_maxlen ?
- 2 * api->users_maxlen : 1;
- struct optional_api_user **new_list =
- realloc(api->users, new_maxlen * sizeof(*new_list));
+ size_t new_maxlen = api->users_maxlen ? 2 * api->users_maxlen : 1;
+ struct optional_api_user **new_list;
+ new_list = ast_std_realloc(api->users, new_maxlen * sizeof(*new_list));
if (!new_list) {
optional_api_user_destroy(user);
ast_log(LOG_ERROR, "Failed to allocate api list\n");
@@ -336,6 +338,7 @@ void ast_optional_api_unuse(const char *symname, ast_optional_fn *optional_ref,
for (i = 0; i < api->users_len; ++i) {
struct optional_api_user *user = api->users[i];
+
if (user->optional_ref == optional_ref) {
if (*user->optional_ref != user->stub) {
ast_verb(4, "%s: stubbing for %s\n", symname,