From 12f6b763d206e5a57e07f45eabd90c7f8c61fd49 Mon Sep 17 00:00:00 2001 From: kpfleming Date: Tue, 5 May 2009 13:00:04 +0000 Subject: Merged revisions 192318 via svnmerge from https://origsvn.digium.com/svn/asterisk/trunk ........ r192318 | kpfleming | 2009-05-05 12:34:19 +0200 (Tue, 05 May 2009) | 5 lines Properly account for memory allocated for channels and datastores As in previous commits, when channels are allocated (with ast_channel_alloc) or datastores are allocated (with ast_datastore_alloc) properly account for the memory being owned by the caller, instead of the allocator function itself. ........ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.2@192355 f38db490-d61c-443f-a65b-d21fe96a405b --- main/channel.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 7 deletions(-) (limited to 'main/channel.c') diff --git a/main/channel.c b/main/channel.c index bc54eabad..44095eac3 100644 --- a/main/channel.c +++ b/main/channel.c @@ -767,13 +767,16 @@ static const struct ast_channel_tech null_tech = { }; /*! \brief Create a new channel structure */ -struct ast_channel *ast_channel_alloc(int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const int amaflag, const char *name_fmt, ...) +static struct ast_channel * attribute_malloc __attribute__((format(printf, 12, 0))) +__ast_channel_alloc_ap(int needqueue, int state, const char *cid_num, const char *cid_name, + const char *acctcode, const char *exten, const char *context, + const int amaflag, const char *file, int line, const char *function, + const char *name_fmt, va_list ap1, va_list ap2) { struct ast_channel *tmp; int x; int flags; struct varshead *headp; - va_list ap1, ap2; /* If shutting down, don't allocate any new channels */ if (shutting_down) { @@ -781,8 +784,15 @@ struct ast_channel *ast_channel_alloc(int needqueue, int state, const char *cid_ return NULL; } - if (!(tmp = ast_calloc(1, sizeof(*tmp)))) +#if defined(__AST_DEBUG_MALLOC) + if (!(tmp = __ast_calloc(1, sizeof(*tmp), file, line, function))) { + return NULL; + } +#else + if (!(tmp = ast_calloc(1, sizeof(*tmp)))) { return NULL; + } +#endif if (!(tmp->sched = sched_context_create())) { ast_log(LOG_WARNING, "Channel allocation failed: Unable to create schedule context\n"); @@ -878,11 +888,7 @@ alertpipe_failed: * uses them to build the string, instead of forming the va_lists internally from the vararg ... list. * This new function was written so this can be accomplished. */ - va_start(ap1, name_fmt); - va_start(ap2, name_fmt); ast_string_field_build_va(tmp, name, name_fmt, ap1, ap2); - va_end(ap1); - va_end(ap2); } /* Reminder for the future: under what conditions do we NOT want to track cdrs on channels? */ @@ -960,6 +966,25 @@ alertpipe_failed: return tmp; } +struct ast_channel *__ast_channel_alloc(int needqueue, int state, const char *cid_num, + const char *cid_name, const char *acctcode, + const char *exten, const char *context, + const int amaflag, const char *file, int line, + const char *function, const char *name_fmt, ...) +{ + va_list ap1, ap2; + struct ast_channel *result; + + va_start(ap1, name_fmt); + va_start(ap2, name_fmt); + result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context, + amaflag, file, line, function, name_fmt, ap1, ap2); + va_end(ap1); + va_end(ap2); + + return result; +} + /*! \brief Queue an outgoing media frame */ static int __ast_queue_frame(struct ast_channel *chan, struct ast_frame *fin, int head) { @@ -5523,3 +5548,37 @@ int ast_say_digits_full(struct ast_channel *chan, int num, return ast_say_digit_str_full(chan, buf, ints, lang, audiofd, ctrlfd); } + +/* DO NOT PUT ADDITIONAL FUNCTIONS BELOW THIS BOUNDARY + * + * ONLY FUNCTIONS FOR PROVIDING BACKWARDS ABI COMPATIBILITY BELONG HERE + * + */ + +/* Provide binary compatibility for modules that call ast_channel_alloc() directly; + * newly compiled modules will call __ast_channel_alloc() via the macros in channel.h + */ +#undef ast_channel_alloc +struct ast_channel __attribute__((format(printf, 9, 10))) + *ast_channel_alloc(int needqueue, int state, const char *cid_num, + const char *cid_name, const char *acctcode, + const char *exten, const char *context, + const int amaflag, const char *name_fmt, ...); +struct ast_channel *ast_channel_alloc(int needqueue, int state, const char *cid_num, + const char *cid_name, const char *acctcode, + const char *exten, const char *context, + const int amaflag, const char *name_fmt, ...) +{ + va_list ap1, ap2; + struct ast_channel *result; + + + va_start(ap1, name_fmt); + va_start(ap2, name_fmt); + result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context, + amaflag, __FILE__, __LINE__, __FUNCTION__, name_fmt, ap1, ap2); + va_end(ap1); + va_end(ap2); + + return result; +} -- cgit v1.2.3