[asterisk-commits] kpfleming: trunk r192318 - in /trunk: include/asterisk/ main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue May 5 05:34:25 CDT 2009
Author: kpfleming
Date: Tue May 5 05:34:19 2009
New Revision: 192318
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=192318
Log:
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.
Modified:
trunk/include/asterisk/astobj2.h
trunk/include/asterisk/channel.h
trunk/include/asterisk/datastore.h
trunk/main/astobj2.c
trunk/main/channel.c
trunk/main/datastore.c
Modified: trunk/include/asterisk/astobj2.h
URL: http://svn.asterisk.org/svn-view/asterisk/trunk/include/asterisk/astobj2.h?view=diff&rev=192318&r1=192317&r2=192318
==============================================================================
--- trunk/include/asterisk/astobj2.h (original)
+++ trunk/include/asterisk/astobj2.h Tue May 5 05:34:19 2009
@@ -402,10 +402,15 @@
* @{
*/
-#if defined(REF_DEBUG) || defined(__AST_DEBUG_MALLOC)
-
-#define ao2_t_alloc(data_size, destructor_fn, debug_msg) __ao2_alloc_debug((data_size), (destructor_fn), (debug_msg), __FILE__, __LINE__, __PRETTY_FUNCTION__)
-#define ao2_alloc(data_size, destructor_fn) __ao2_alloc_debug((data_size), (destructor_fn), "", __FILE__, __LINE__, __PRETTY_FUNCTION__)
+#if defined(REF_DEBUG)
+
+#define ao2_t_alloc(data_size, destructor_fn, debug_msg) __ao2_alloc_debug((data_size), (destructor_fn), (debug_msg), __FILE__, __LINE__, __PRETTY_FUNCTION__, 1)
+#define ao2_alloc(data_size, destructor_fn) __ao2_alloc_debug((data_size), (destructor_fn), "", __FILE__, __LINE__, __PRETTY_FUNCTION__, 1)
+
+#elif defined(__AST_DEBUG_MALLOC)
+
+#define ao2_t_alloc(data_size, destructor_fn, debug_msg) __ao2_alloc_debug((data_size), (destructor_fn), (debug_msg), __FILE__, __LINE__, __PRETTY_FUNCTION__, 0)
+#define ao2_alloc(data_size, destructor_fn) __ao2_alloc_debug((data_size), (destructor_fn), "", __FILE__, __LINE__, __PRETTY_FUNCTION__, 0)
#else
@@ -414,7 +419,8 @@
#endif
-void *__ao2_alloc_debug(const size_t data_size, ao2_destructor_fn destructor_fn, char *tag, char *file, int line, const char *funcname);
+void *__ao2_alloc_debug(const size_t data_size, ao2_destructor_fn destructor_fn, char *tag,
+ const char *file, int line, const char *funcname, int ref_debug);
void *__ao2_alloc(const size_t data_size, ao2_destructor_fn destructor_fn);
/*! @} */
@@ -698,10 +704,15 @@
* destructor is set implicitly.
*/
-#if defined(REF_DEBUG) || defined(__AST_DEBUG_MALLOC)
-
-#define ao2_t_container_alloc(arg1,arg2,arg3,arg4) __ao2_container_alloc_debug((arg1), (arg2), (arg3), (arg4), __FILE__, __LINE__, __PRETTY_FUNCTION__)
-#define ao2_container_alloc(arg1,arg2,arg3) __ao2_container_alloc_debug((arg1), (arg2), (arg3), "", __FILE__, __LINE__, __PRETTY_FUNCTION__)
+#if defined(REF_DEBUG)
+
+#define ao2_t_container_alloc(arg1,arg2,arg3,arg4) __ao2_container_alloc_debug((arg1), (arg2), (arg3), (arg4), __FILE__, __LINE__, __PRETTY_FUNCTION__, 1)
+#define ao2_container_alloc(arg1,arg2,arg3) __ao2_container_alloc_debug((arg1), (arg2), (arg3), "", __FILE__, __LINE__, __PRETTY_FUNCTION__, 1)
+
+#elif defined(__AST_DEBUG_MALLOC)
+
+#define ao2_t_container_alloc(arg1,arg2,arg3,arg4) __ao2_container_alloc_debug((arg1), (arg2), (arg3), (arg4), __FILE__, __LINE__, __PRETTY_FUNCTION__, 0)
+#define ao2_container_alloc(arg1,arg2,arg3) __ao2_container_alloc_debug((arg1), (arg2), (arg3), "", __FILE__, __LINE__, __PRETTY_FUNCTION__, 0)
#else
@@ -714,7 +725,8 @@
ao2_hash_fn *hash_fn, ao2_callback_fn *cmp_fn);
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);
+ char *tag, char *file, int line, const char *funcname,
+ int ref_debug);
/*! \brief
* Returns the number of elements in a container.
Modified: trunk/include/asterisk/channel.h
URL: http://svn.asterisk.org/svn-view/asterisk/trunk/include/asterisk/channel.h?view=diff&rev=192318&r1=192317&r2=192318
==============================================================================
--- trunk/include/asterisk/channel.h (original)
+++ trunk/include/asterisk/channel.h Tue May 5 05:34:19 2009
@@ -854,7 +854,7 @@
* \deprecated You should use the ast_datastore_alloc() generic function instead.
* \version 1.6.1 deprecated
*/
-struct ast_datastore *ast_channel_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
+struct ast_datastore * attribute_malloc ast_channel_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
__attribute__((deprecated));
/*!
@@ -913,7 +913,16 @@
* \note By default, new channels are set to the "s" extension
* and "default" context.
*/
-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, ...) __attribute__((format(printf, 9, 10)));
+struct ast_channel * attribute_malloc __attribute__((format(printf, 12, 13)))
+ __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, ...);
+
+#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, amaflag, ...) \
+ __ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, amaflag, \
+ __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
/*!
* \brief Queue an outgoing frame
Modified: trunk/include/asterisk/datastore.h
URL: http://svn.asterisk.org/svn-view/asterisk/trunk/include/asterisk/datastore.h?view=diff&rev=192318&r1=192317&r2=192318
==============================================================================
--- trunk/include/asterisk/datastore.h (original)
+++ trunk/include/asterisk/datastore.h Tue May 5 05:34:19 2009
@@ -65,7 +65,10 @@
* \param[in] uid unique identifer
* \version 1.6.1 moved here and renamed from ast_channel_datastore_alloc
*/
-struct ast_datastore *ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid);
+struct ast_datastore * attribute_malloc __ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid,
+ const char *file, int line, const char *function);
+
+#define ast_datastore_alloc(info, uid) __ast_datastore_alloc(info, uid, __FILE__, __LINE__, __PRETTY_FUNCTION__)
/*!
* \brief Free a data store object
Modified: trunk/main/astobj2.c
URL: http://svn.asterisk.org/svn-view/asterisk/trunk/main/astobj2.c?view=diff&rev=192318&r1=192317&r2=192318
==============================================================================
--- trunk/main/astobj2.c (original)
+++ trunk/main/astobj2.c Tue May 5 05:34:19 2009
@@ -302,7 +302,7 @@
* We always alloc at least the size of a void *,
* for debugging purposes.
*/
-static void *internal_ao2_alloc(size_t data_size, ao2_destructor_fn destructor_fn, char *file, int line, const char *funcname)
+static void *internal_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 @@
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 = internal_ao2_alloc(data_size, destructor_fn, file, line, funcname);
@@ -443,13 +444,14 @@
}
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 */
const unsigned int num_buckets = hash_fn ? n_buckets : 1;
size_t container_size = sizeof(struct ao2_container) + num_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 internal_ao2_container_alloc(c, num_buckets, hash_fn, cmp_fn);
}
Modified: trunk/main/channel.c
URL: http://svn.asterisk.org/svn-view/asterisk/trunk/main/channel.c?view=diff&rev=192318&r1=192317&r2=192318
==============================================================================
--- trunk/main/channel.c (original)
+++ trunk/main/channel.c Tue May 5 05:34:19 2009
@@ -779,13 +779,16 @@
static void ast_channel_destructor(void *obj);
/*! \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) {
@@ -793,9 +796,19 @@
return NULL;
}
+#if defined(REF_DEBUG)
+ if (!(tmp = __ao2_alloc_debug(sizeof(*tmp), ast_channel_destructor, "", file, line, function, 1))) {
+ return NULL;
+ }
+#elif defined(__AST_DEBUG_MALLOC)
+ if (!(tmp = __ao2_alloc_debug(sizeof(*tmp), ast_channel_destructor, "", file, line, function, 0))) {
+ return NULL;
+ }
+#else
if (!(tmp = ao2_alloc(sizeof(*tmp), ast_channel_destructor))) {
return NULL;
}
+#endif
if (!(tmp->sched = sched_context_create())) {
ast_log(LOG_WARNING, "Channel allocation failed: Unable to create schedule context\n");
@@ -908,11 +921,7 @@
* 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? */
@@ -986,6 +995,25 @@
}
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 */
@@ -6474,3 +6502,36 @@
ast_queue_control_data(chan, AST_CONTROL_REDIRECTING, data, datalen);
}
+/* 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;
+}
Modified: trunk/main/datastore.c
URL: http://svn.asterisk.org/svn-view/asterisk/trunk/main/datastore.c?view=diff&rev=192318&r1=192317&r2=192318
==============================================================================
--- trunk/main/datastore.c (original)
+++ trunk/main/datastore.c Tue May 5 05:34:19 2009
@@ -28,7 +28,8 @@
#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 @@
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 @@
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__);
+}
More information about the asterisk-commits
mailing list