pjproject: Add cache_pools debugging option.

The pool cache gets in the way of finding use after free errors of memory
pool contents.  Tools like valgrind and MALLOC_DEBUG don't know when a
pool is released because it gets put into the cache instead of being
freed.

* Added the "cache_pools" option to pjproject.conf.  Disabling the option
helps track down pool content mismanagement when using valgrind or
MALLOC_DEBUG.  The cache gets in the way of determining if the pool
contents are used after free and who freed it.

To disable the pool caching simply disable the cache_pools option in
pjproject.conf and restart Asterisk.

Sample pjproject.conf setting:
[startup]
cache_pools=no

* Made current users of the caching pool factory initialization and
destruction calls call common routines to create and destroy cached pools.

ASTERISK-27704

Change-Id: I64d5befbaeed2532f93aa027a51eb52347d2b828
This commit is contained in:
Richard Mudgett
2018-02-27 15:40:18 -06:00
parent 68df9e609e
commit 104468ad3a
10 changed files with 77 additions and 8 deletions

View File

@@ -173,6 +173,11 @@ enum ast_option_flags {
/*! Current linked pjproject maximum logging level */
extern int ast_pjproject_max_log_level;
#define DEFAULT_PJPROJECT_CACHE_POOLS 1
/*! Current pjproject pool caching enable */
extern int ast_option_pjproject_cache_pools;
/*! Current pjproject logging level */
extern int ast_option_pjproject_log_level;

View File

@@ -19,6 +19,9 @@
#ifndef _RES_PJPROJECT_H
#define _RES_PJPROJECT_H
#include <pj/types.h>
#include <pj/pool.h>
/*! \brief Determines whether the res_pjproject module is loaded */
#define CHECK_PJPROJECT_MODULE_LOADED() \
do { \
@@ -93,4 +96,27 @@ void ast_pjproject_ref(void);
*/
void ast_pjproject_unref(void);
/*!
* \brief Initialize the caching pool factory.
* \since 13.21.0
*
* \param cp Caching pool factory to initialize
* \param policy Pool factory policy
* \param max_capacity Total capacity to be retained in the cache. Zero disables caching.
*
* \return Nothing
*/
void ast_pjproject_caching_pool_init(pj_caching_pool *cp,
const pj_pool_factory_policy *policy, pj_size_t max_capacity);
/*!
* \brief Destroy caching pool factory and all cached pools.
* \since 13.21.0
*
* \param cp Caching pool factory to destroy
*
* \return Nothing
*/
void ast_pjproject_caching_pool_destroy(pj_caching_pool *cp);
#endif /* _RES_PJPROJECT_H */