[asterisk-commits] dhubbard: branch dhubbard/named_processors r108287 - /team/dhubbard/named_pro...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Mar 12 16:47:47 CDT 2008
Author: dhubbard
Date: Wed Mar 12 16:47:46 2008
New Revision: 108287
URL: http://svn.digium.com/view/asterisk?view=rev&rev=108287
Log:
use ast_calloc and ast_free instead of malloc, memset, and free
Modified:
team/dhubbard/named_processors/res/sandbox/configuration.c
team/dhubbard/named_processors/res/sandbox/simobject.c
team/dhubbard/named_processors/res/sandbox/task.c
team/dhubbard/named_processors/res/sandbox/taskconsumer.c
team/dhubbard/named_processors/res/sandbox/taskprocessor.c
team/dhubbard/named_processors/res/sandbox/taskproducer.c
Modified: team/dhubbard/named_processors/res/sandbox/configuration.c
URL: http://svn.digium.com/view/asterisk/team/dhubbard/named_processors/res/sandbox/configuration.c?view=diff&rev=108287&r1=108286&r2=108287
==============================================================================
--- team/dhubbard/named_processors/res/sandbox/configuration.c (original)
+++ team/dhubbard/named_processors/res/sandbox/configuration.c Wed Mar 12 16:47:46 2008
@@ -90,12 +90,8 @@
static int __resx_add_config_option_value(int index, void* value, size_t size)
{
if (!resx_config_options[index].value) {
- resx_config_options[index].value = malloc(size+1);
- memset(resx_config_options[index].value, 0, size+1);
- if (resx_config_options[index].value) {
- memcpy(resx_config_options[index].value, value, size);
- return 0;
- }
+ resx_config_options[index].value = ast_strdup(value);
+ return 0;
}
return -1;
}
@@ -112,7 +108,7 @@
int __resx_update_config_option_value(int index, void* value, size_t size)
{
if (resx_config_options[index].value) {
- free(resx_config_options[index].value);
+ ast_free(resx_config_options[index].value);
resx_config_options[index].value = 0;
}
return __resx_add_config_option_value(index, value, size);
Modified: team/dhubbard/named_processors/res/sandbox/simobject.c
URL: http://svn.digium.com/view/asterisk/team/dhubbard/named_processors/res/sandbox/simobject.c?view=diff&rev=108287&r1=108286&r2=108287
==============================================================================
--- team/dhubbard/named_processors/res/sandbox/simobject.c (original)
+++ team/dhubbard/named_processors/res/sandbox/simobject.c Wed Mar 12 16:47:46 2008
@@ -35,12 +35,11 @@
, named_taskprocessor, name);
return NULL;
}
- s = malloc(sizeof(struct simobject));
+ s = ast_calloc(1, sizeof(*s));
if (!s) {
ast_log(LOG_ERROR, "cannot allocate memory for a simobject structure.\n");
return NULL;
}
- memset(s, 0, sizeof(struct simobject));
snprintf(s->_name, sizeof(s->_name), "%s", name);
s->_producer = construct_taskproducer(t);
s->_consumer = construct_taskconsumer(s, t);
@@ -62,12 +61,11 @@
, named_taskprocessor, name);
return NULL;
}
- s = malloc(sizeof(struct simobject));
+ s = ast_calloc(1, sizeof(*s));
if (!s) {
ast_log(LOG_ERROR, "cannot allocate memory for a simobject structure.\n");
return NULL;
}
- memset(s, 0, sizeof(struct simobject));
snprintf(s->_name, sizeof(s->_name), "%s", name);
snprintf(tpg, sizeof(tpg), "%s-generator", s->_name);
s->_producer = construct_taskproducer(t);
@@ -75,14 +73,14 @@
if (!exists_taskprocessor_singleton(tpg)) {
if (create_taskprocessor_singleton(tpg, _simproducer_thread_function) < 0) {
ast_log(LOG_ERROR, "can't create \'%s\' taskprocessor singleton\n", tpg);
- free(s);
+ ast_free(s);
return NULL;
}
}
s->_taskgenerator = get_taskprocessor_singleton(tpg);
if (!s->_taskgenerator) {
ast_log(LOG_ERROR, "Huh? we don't have a task generator called \'%s\' ??\n", tpg);
- free(s);
+ ast_free(s);
return NULL;
}
ast_log(LOG_DEBUG, "simobject at 0x%ld (taskgenerator: 0x%ld) setting private to 0x%ld\n", (unsigned long)&s, (unsigned long)s->_taskgenerator, (unsigned long)&s);
@@ -104,12 +102,11 @@
, named_taskprocessor, name);
return NULL;
}
- s = malloc(sizeof(struct simobject));
+ s = ast_calloc(1, sizeof(*s));
if (!s) {
ast_log(LOG_ERROR, "cannot allocate memory for a simobject structure.\n");
return NULL;
}
- memset(s, 0, sizeof(struct simobject));
snprintf(s->_name, sizeof(s->_name), "%s", name);
s->_consumer = construct_taskconsumer(s, t);
s->start = start_simobject;
Modified: team/dhubbard/named_processors/res/sandbox/task.c
URL: http://svn.digium.com/view/asterisk/team/dhubbard/named_processors/res/sandbox/task.c?view=diff&rev=108287&r1=108286&r2=108287
==============================================================================
--- team/dhubbard/named_processors/res/sandbox/task.c (original)
+++ team/dhubbard/named_processors/res/sandbox/task.c Wed Mar 12 16:47:46 2008
@@ -116,7 +116,7 @@
{
int lock_failures = 0;
if (t->_datap) {
- free(t->_datap);
+ ast_free(t->_datap);
}
memset(t, 0, sizeof(struct a_task));
AST_LIST_LOCK(&_task_pool);
@@ -154,7 +154,7 @@
while (!AST_LIST_EMPTY(&_task_pool)) {
t = AST_LIST_REMOVE_HEAD(&_task_pool, list);
if (t) {
- free(t);
+ ast_free(t);
t = NULL;
}
_task_pool_size -= 1;
Modified: team/dhubbard/named_processors/res/sandbox/taskconsumer.c
URL: http://svn.digium.com/view/asterisk/team/dhubbard/named_processors/res/sandbox/taskconsumer.c?view=diff&rev=108287&r1=108286&r2=108287
==============================================================================
--- team/dhubbard/named_processors/res/sandbox/taskconsumer.c (original)
+++ team/dhubbard/named_processors/res/sandbox/taskconsumer.c Wed Mar 12 16:47:46 2008
@@ -38,12 +38,11 @@
struct taskconsumer* construct_taskconsumer(void* owner, struct taskprocessor_singleton_info* processor)
{
struct taskconsumer* c = NULL;
- c = malloc(sizeof(struct taskconsumer));
+ c = ast_calloc(1, sizeof(*c));
if (!c) {
ast_log(LOG_ERROR, "cannot allocate memory for a taskconsumer structure.\n");
return NULL;
}
- memset(c, 0, sizeof(struct taskconsumer));
c->_owner = owner;
c->_taskprocessor = processor;
c->handle_task = invalid_handle_task;
Modified: team/dhubbard/named_processors/res/sandbox/taskprocessor.c
URL: http://svn.digium.com/view/asterisk/team/dhubbard/named_processors/res/sandbox/taskprocessor.c?view=diff&rev=108287&r1=108286&r2=108287
==============================================================================
--- team/dhubbard/named_processors/res/sandbox/taskprocessor.c (original)
+++ team/dhubbard/named_processors/res/sandbox/taskprocessor.c Wed Mar 12 16:47:46 2008
@@ -237,13 +237,12 @@
static struct taskprocessor_singleton_info* default_taskprocessor_constructor(int poll_freq)
{
- struct taskprocessor_singleton_info* t = NULL;
- t = malloc(sizeof(struct taskprocessor_singleton_info));
+ struct taskprocessor_singleton_info* t;
+ t = ast_calloc(1, sizeof(*t));
if (!t) {
ast_log(LOG_ERROR, "cannot allocate memory for a taskprocessor_singleton_info structure.\n");
return NULL;
}
- memset(t, 0, sizeof(struct taskprocessor_singleton_info));
t->_id = (unsigned long)t;
if (poll_freq < 1)
t->_poll_freq = DEFAULT_POLL_FREQUENCY;
@@ -251,14 +250,12 @@
t->_poll_freq = poll_freq;
ast_cond_init(&t->_poll_cond, NULL);
t->_poll_thread = AST_PTHREADT_NULL;
- t->_stats = malloc(sizeof(struct taskprocessor_singleton_stats));
+ t->_stats = ast_calloc(1, sizeof(*t->_stats));
if (!t->_stats) {
ast_log(LOG_ERROR, "cannot allocate memory for a taskprocessor_singleton_stats structure.\n");
- free(t);
+ ast_free(t);
return NULL;
}
- memset(t->_stats, 0, sizeof(struct taskprocessor_singleton_stats));
- ast_log(LOG_DEBUG, "default constructor created \'%s\' at 0x%ld\n", t->_name, (unsigned long)t);
return t;
}
@@ -349,10 +346,10 @@
ast_log(LOG_WARNING, "cannot remove taskprocessor_singleton \'%s\'.\n", t->_name);
}
if (t->_stats) {
- free(t->_stats);
+ ast_free(t->_stats);
t->_stats = NULL;
}
- free(t);
+ ast_free(t);
t = NULL;
return 0;
}
Modified: team/dhubbard/named_processors/res/sandbox/taskproducer.c
URL: http://svn.digium.com/view/asterisk/team/dhubbard/named_processors/res/sandbox/taskproducer.c?view=diff&rev=108287&r1=108286&r2=108287
==============================================================================
--- team/dhubbard/named_processors/res/sandbox/taskproducer.c (original)
+++ team/dhubbard/named_processors/res/sandbox/taskproducer.c Wed Mar 12 16:47:46 2008
@@ -45,13 +45,12 @@
/* create and initialize a task producer */
struct taskproducer* construct_taskproducer(struct taskprocessor_singleton_info* processor)
{
- struct taskproducer* p = NULL;
- p = malloc(sizeof(struct taskproducer));
+ struct taskproducer* p;
+ p = ast_calloc(1, sizeof(*p));
if (!p) {
ast_log(LOG_ERROR, "cannot allocate memory for a taskproducer structure.\n");
return NULL;
}
- memset(p, 0, sizeof(struct taskproducer));
p->_taskprocessor = processor;
p->queue_task = default_queue_task;
return p;
More information about the asterisk-commits
mailing list