aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2009-05-05 13:00:04 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2009-05-05 13:00:04 +0000
commit12f6b763d206e5a57e07f45eabd90c7f8c61fd49 (patch)
treed3359456f178cd1af1e2b160bf2674b9334b95f8 /main
parenta01063165d8e8500f6a55f4abafe5e52f72e7596 (diff)
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
Diffstat (limited to 'main')
-rw-r--r--main/astobj2.c12
-rw-r--r--main/channel.c73
-rw-r--r--main/datastore.c29
3 files changed, 98 insertions, 16 deletions
diff --git a/main/astobj2.c b/main/astobj2.c
index 416632ff2..cf3b2c821 100644
--- a/main/astobj2.c
+++ b/main/astobj2.c
@@ -302,7 +302,7 @@ static int __ao2_ref(void *user_data, const int delta)
* We always alloc at least the size of a void *,
* for debugging purposes.
*/
-static void *__ao2_alloc(size_t data_size, ao2_destructor_fn destructor_fn, char *file, int line, const char *funcname)
+static void *__ao2_alloc(size_t data_size, ao2_destructor_fn destructor_fn, const char *file, int line, const char *funcname)
{
/* allocation */
struct astobj2 *obj;
@@ -335,11 +335,12 @@ static void *__ao2_alloc(size_t data_size, ao2_destructor_fn destructor_fn, char
return EXTERNAL_OBJ(obj);
}
-void *_ao2_alloc_debug(size_t data_size, ao2_destructor_fn destructor_fn, char *tag, char *file, int line, const char *funcname)
+void *_ao2_alloc_debug(size_t data_size, ao2_destructor_fn destructor_fn, char *tag,
+ const char *file, int line, const char *funcname, int ref_debug)
{
/* allocation */
void *obj;
- FILE *refo = fopen(REF_FILE,"a");
+ FILE *refo = ref_debug ? fopen(REF_FILE,"a") : NULL;
obj = __ao2_alloc(data_size, destructor_fn, file, line, funcname);
@@ -443,12 +444,13 @@ static struct ao2_container *__ao2_container_alloc(struct ao2_container *c, cons
}
struct ao2_container *_ao2_container_alloc_debug(const unsigned int n_buckets, ao2_hash_fn *hash_fn,
- ao2_callback_fn *cmp_fn, char *tag, char *file, int line, const char *funcname)
+ ao2_callback_fn *cmp_fn, char *tag, char *file, int line,
+ const char *funcname, int ref_debug)
{
/* XXX maybe consistency check on arguments ? */
/* compute the container size */
size_t container_size = sizeof(struct ao2_container) + n_buckets * sizeof(struct bucket);
- struct ao2_container *c = _ao2_alloc_debug(container_size, container_destruct_debug, tag, file, line, funcname);
+ struct ao2_container *c = _ao2_alloc_debug(container_size, container_destruct_debug, tag, file, line, funcname, ref_debug);
return __ao2_container_alloc(c, n_buckets, hash_fn, cmp_fn);
}
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;
+}
diff --git a/main/datastore.c b/main/datastore.c
index be5479796..3d097860f 100644
--- a/main/datastore.c
+++ b/main/datastore.c
@@ -28,7 +28,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/datastore.h"
#include "asterisk/utils.h"
-struct ast_datastore *ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
+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;
@@ -37,11 +38,15 @@ struct ast_datastore *ast_datastore_alloc(const struct ast_datastore_info *info,
return NULL;
}
- /* Allocate memory for datastore and clear it */
- datastore = ast_calloc(1, sizeof(*datastore));
- if (!datastore) {
+#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;
@@ -71,3 +76,19 @@ int ast_datastore_free(struct ast_datastore *datastore)
return res;
}
+
+/* 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_datastore_alloc() directly;
+ * newly compiled modules will call __ast_datastore_alloc() via the macros in datastore.h
+ */
+#undef ast_datastore_alloc
+struct ast_datastore *ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid);
+struct ast_datastore *ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
+{
+ return __ast_datastore_alloc(info, uid, __FILE__, __LINE__, __FUNCTION__);
+}