Ensure that string pools allocated to hold stringfields are properly accounted in MALLOC_DEBUG mode

This commit modifies the stringfield pool allocator to remember the 'owner' of the stringfield manager the pool is being allocated for, and ensures that pools allocated in the future when fields are populated are owned by that file/function.



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@192279 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Kevin P. Fleming
2009-05-05 08:51:06 +00:00
parent 0d44a84870
commit d8182202ef
2 changed files with 55 additions and 24 deletions

View File

@@ -137,7 +137,12 @@ struct ast_string_field_pool {
\brief Structure used to manage the storage for a set of string fields.
*/
struct ast_string_field_mgr {
ast_string_field last_alloc; /*!< the last field allocated */
ast_string_field last_alloc; /*!< the last field allocated */
#if defined(__AST_DEBUG_MALLOC)
const char *owner_file; /*!< filename of owner */
const char *owner_func; /*!< function name of owner */
int owner_line; /*!< line number of owner */
#endif
};
/*!
@@ -235,15 +240,18 @@ void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr,
\return 0 on success, non-zero on failure
*/
#define ast_string_field_init(x, size) \
__ast_string_field_init(&(x)->__field_mgr, &(x)->__field_mgr_pool, size)
__ast_string_field_init(&(x)->__field_mgr, &(x)->__field_mgr_pool, size, __FILE__, __LINE__, __PRETTY_FUNCTION__)
/*! \brief free all memory - to be called before destroying the object */
#define ast_string_field_free_memory(x) \
__ast_string_field_init(&(x)->__field_mgr, &(x)->__field_mgr_pool, -1)
__ast_string_field_init(&(x)->__field_mgr, &(x)->__field_mgr_pool, -1, NULL, 0, NULL)
/*! \internal \brief internal version of ast_string_field_init */
int __ast_string_field_init(struct ast_string_field_mgr *mgr,
struct ast_string_field_pool **pool_head, int needed);
/*!
* \internal
* \brief internal version of ast_string_field_init
*/
int __ast_string_field_init(struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head,
int needed, const char *file, int lineno, const char *func);
/*!
\internal