diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-02-09 16:59:50 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-02-09 16:59:50 +0000 |
commit | 34490de229310cffd8ee332e86e9e1018aaa57f5 (patch) | |
tree | bc582fc8d1412250a1a150dcaf06bfb7fe76e0c2 /db.c | |
parent | 0a2b114fb5907f90ec49f443931fffdb79a89d55 (diff) |
conversions to memory allocation wrappers, remove duplicated error messages,
remove unnecessary casts, malloc+memset to calloc (issue #6395)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@9310 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'db.c')
-rw-r--r-- | db.c | 36 |
1 files changed, 16 insertions, 20 deletions
@@ -63,14 +63,11 @@ AST_MUTEX_DEFINE_STATIC(dblock); static int dbinit(void) { - if (!astdb) { - if (!(astdb = dbopen((char *)ast_config_AST_DB, O_CREAT | O_RDWR, 0664, DB_BTREE, NULL))) { - ast_log(LOG_WARNING, "Unable to open Asterisk database\n"); - } + if (!astdb && !(astdb = dbopen((char *)ast_config_AST_DB, O_CREAT | O_RDWR, 0664, DB_BTREE, NULL))) { + ast_log(LOG_WARNING, "Unable to open Asterisk database\n"); + return -1; } - if (astdb) - return 0; - return -1; + return 0; } @@ -402,6 +399,7 @@ struct ast_db_entry *ast_db_gettree(const char *family, const char *keytree) char prefix[256]; DBT key, data; char *keys, *values; + int values_len; int res; int pass; struct ast_db_entry *last = NULL; @@ -440,20 +438,18 @@ struct ast_db_entry *ast_db_gettree(const char *family, const char *keytree) } else { values = "<bad value>"; } - if (keymatch(keys, prefix)) { - cur = malloc(sizeof(struct ast_db_entry) + strlen(keys) + strlen(values) + 2); - if (cur) { - cur->next = NULL; - cur->key = cur->data + strlen(values) + 1; - strcpy(cur->data, values); - strcpy(cur->key, keys); - if (last) { - last->next = cur; - } else { - ret = cur; - } - last = cur; + values_len = strlen(values) + 1; + if (keymatch(keys, prefix) && (cur = ast_malloc(sizeof(*cur) + strlen(keys) + 1 + values_len))) { + cur->next = NULL; + cur->key = cur->data + values_len; + strcpy(cur->data, values); + strcpy(cur->key, keys); + if (last) { + last->next = cur; + } else { + ret = cur; } + last = cur; } } ast_mutex_unlock(&dblock); |