Index: include/asterisk/astobj2.h =================================================================== --- include/asterisk/astobj2.h (revision 182446) +++ include/asterisk/astobj2.h (working copy) @@ -162,7 +162,12 @@ * - the returned pointer cannot be free()'d or realloc()'ed; * rather, we just call ao2_ref(o, -1); */ +#if defined(MALLOC_DEBUG) && !defined(STANDALONE) +void *_ao2_alloc(const size_t data_size, ao2_destructor_fn destructor_fn, const char *file, int lineno, const char *func); +#define ao2_alloc(a,b) _ao2_alloc(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__) +#else void *ao2_alloc(const size_t data_size, ao2_destructor_fn destructor_fn); +#endif /*! \brief * Reference/unreference an object and return the old refcount. @@ -368,8 +373,15 @@ * * destructor is set implicitly. */ +#if defined(MALLOC_DEBUG) && !defined(STANDALONE) +struct ao2_container *_ao2_container_alloc(const unsigned int n_buckets, + ao2_hash_fn *hash_fn, ao2_callback_fn *cmp_fn, + const char *file, int lineno, const char *func); +#define ao2_container_alloc(a,b,c) _ao2_container_alloc(a,b,c,__FILE__,__LINE__,__PRETTY_FUNCTION__) +#else struct ao2_container *ao2_container_alloc(const unsigned int n_buckets, ao2_hash_fn *hash_fn, ao2_callback_fn *cmp_fn); +#endif /*! \brief * Returns the number of elements in a container. @@ -401,7 +413,12 @@ * \note This function automatically increases the reference count to account * for the reference that the container now holds to the object. */ +#if defined(MALLOC_DEBUG) && !defined(STANDALONE) +void *_ao2_link(struct ao2_container *c, void *newobj, const char *file, int lineno, const char *func); +#define ao2_link(a,b) _ao2_link(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__) +#else void *ao2_link(struct ao2_container *c, void *newobj); +#endif /*! * \brief Remove an object from the container Index: main/astobj2.c =================================================================== --- main/astobj2.c (revision 182446) +++ main/astobj2.c (working copy) @@ -245,7 +245,11 @@ * We always alloc at least the size of a void *, * for debugging purposes. */ +#if defined(MALLOC_DEBUG) && !defined(STANDALONE) +void *_ao2_alloc(size_t data_size, ao2_destructor_fn destructor_fn, const char *file, int lineno, const char *func) +#else void *ao2_alloc(size_t data_size, ao2_destructor_fn destructor_fn) +#endif { /* allocation */ struct astobj2 *obj; @@ -253,7 +257,11 @@ if (data_size < sizeof(void *)) data_size = sizeof(void *); +#if defined(MALLOC_DEBUG) && !defined(STANDALONE) + obj = __ast_calloc(1, sizeof(*obj) + data_size, file, lineno, func); +#else obj = ast_calloc(1, sizeof(*obj) + data_size); +#endif if (obj == NULL) return NULL; @@ -332,14 +340,23 @@ * A container is just an object, after all! */ struct ao2_container * +#if defined(MALLOC_DEBUG) && !defined(STANDALONE) +_ao2_container_alloc(const unsigned int n_buckets, ao2_hash_fn *hash_fn, + ao2_callback_fn *cmp_fn, const char *file, int lineno, const char *func) +#else ao2_container_alloc(const unsigned int n_buckets, ao2_hash_fn *hash_fn, ao2_callback_fn *cmp_fn) +#endif { /* XXX maybe consistency check on arguments ? */ /* compute the container size */ size_t container_size = sizeof(struct ao2_container) + n_buckets * sizeof(struct bucket); +#if defined(MALLOC_DEBUG) && !defined(STANDALONE) + struct ao2_container *c = _ao2_alloc(container_size, container_destruct, file, lineno, func); +#else struct ao2_container *c = ao2_alloc(container_size, container_destruct); +#endif if (!c) return NULL; @@ -378,7 +395,11 @@ /* * link an object to a container */ +#if defined(MALLOC_DEBUG) && !defined(STANDALONE) +void *_ao2_link(struct ao2_container *c, void *user_data, const char *file, int lineno, const char *func) +#else void *ao2_link(struct ao2_container *c, void *user_data) +#endif { int i; /* create a new list entry */ @@ -391,7 +412,11 @@ if (INTERNAL_OBJ(c) == NULL) return NULL; +#if defined(MALLOC_DEBUG) && !defined(STANDALONE) + p = __ast_calloc(1, sizeof(*p), file, lineno, func); +#else p = ast_calloc(1, sizeof(*p)); +#endif if (!p) return NULL;