diff options
author | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-10-14 22:42:17 +0000 |
---|---|---|
committer | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-10-14 22:42:17 +0000 |
commit | 89864095c8d4436d98f75d4a1c338b3c96fede1f (patch) | |
tree | eb21c5f9de5ae6021204bac80e1e8380749c999e /include | |
parent | 04b34fd8e132320704f5f7daebba3948d93b2a3d (diff) |
Merged revisions 149199 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
........
r149199 | tilghman | 2008-10-14 17:38:06 -0500 (Tue, 14 Oct 2008) | 8 lines
Add additional memory debugging to several core APIs, and fix several memory
leaks found with these changes.
(Closes issue #13505, closes issue #13543)
Reported by: mav3rick, triccyx
Patches:
20081001__bug13505.diff.txt uploaded by Corydon76 (license 14)
Tested by: mav3rick, triccyx
........
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.1@149202 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include')
-rw-r--r-- | include/asterisk/chanvars.h | 5 | ||||
-rw-r--r-- | include/asterisk/config.h | 5 | ||||
-rw-r--r-- | include/asterisk/hashtab.h | 10 | ||||
-rw-r--r-- | include/asterisk/strings.h | 25 |
4 files changed, 45 insertions, 0 deletions
diff --git a/include/asterisk/chanvars.h b/include/asterisk/chanvars.h index 63de58429..7ebc64a9d 100644 --- a/include/asterisk/chanvars.h +++ b/include/asterisk/chanvars.h @@ -33,7 +33,12 @@ struct ast_var_t { AST_LIST_HEAD_NOLOCK(varshead, ast_var_t); +#ifdef MALLOC_DEBUG +struct ast_var_t *_ast_var_assign(const char *name, const char *value, const char *file, int lineno, const char *function); +#define ast_var_assign(a,b) _ast_var_assign(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__) +#else struct ast_var_t *ast_var_assign(const char *name, const char *value); +#endif void ast_var_delete(struct ast_var_t *var); const char *ast_var_name(const struct ast_var_t *var); const char *ast_var_full_name(const struct ast_var_t *var); diff --git a/include/asterisk/config.h b/include/asterisk/config.h index a12d12bf6..cb9f8a9f6 100644 --- a/include/asterisk/config.h +++ b/include/asterisk/config.h @@ -332,7 +332,12 @@ void ast_category_destroy(struct ast_category *cat); struct ast_variable *ast_category_detach_variables(struct ast_category *cat); void ast_category_rename(struct ast_category *cat, const char *name); +#ifdef MALLOC_DEBUG +struct ast_variable *_ast_variable_new(const char *name, const char *value, const char *filename, const char *file, const char *function, int lineno); +#define ast_variable_new(a, b, c) _ast_variable_new(a, b, c, __FILE__, __PRETTY_FUNCTION__, __LINE__) +#else struct ast_variable *ast_variable_new(const char *name, const char *value, const char *filename); +#endif struct ast_config_include *ast_include_new(struct ast_config *conf, const char *from_file, const char *included_file, int is_exec, const char *exec_file, int from_lineno, char *real_included_file_name, int real_included_file_name_size); struct ast_config_include *ast_include_find(struct ast_config *conf, const char *included_file); void ast_include_rename(struct ast_config *conf, const char *from_file, const char *to_file); diff --git a/include/asterisk/hashtab.h b/include/asterisk/hashtab.h index aa4dc59db..dbecaa2bc 100644 --- a/include/asterisk/hashtab.h +++ b/include/asterisk/hashtab.h @@ -189,12 +189,22 @@ unsigned int ast_hashtab_hash_short(const short num); * \param hash a func ptr to do the hashing * \param do_locking use locks to guarantee safety of iterators/insertion/deletion -- real simpleminded right now */ +#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +struct ast_hashtab * _ast_hashtab_create(int initial_buckets, + int (*compare)(const void *a, const void *b), + int (*resize)(struct ast_hashtab *), + int (*newsize)(struct ast_hashtab *tab), + unsigned int (*hash)(const void *obj), + int do_locking, const char *file, int lineno, const char *function); +#define ast_hashtab_create(a,b,c,d,e,f) _ast_hashtab_create(a,b,c,d,e,f,__FILE__,__LINE__,__PRETTY_FUNCTION__) +#else struct ast_hashtab * ast_hashtab_create(int initial_buckets, int (*compare)(const void *a, const void *b), int (*resize)(struct ast_hashtab *), int (*newsize)(struct ast_hashtab *tab), unsigned int (*hash)(const void *obj), int do_locking ); +#endif /*! * \brief This func will free the hash table and all its memory. diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h index 514b3af6a..f6239121a 100644 --- a/include/asterisk/strings.h +++ b/include/asterisk/strings.h @@ -404,6 +404,30 @@ void ast_str_reset(struct ast_str *buf), /*! * Make space in a new string (e.g. to read in data from a file) */ +#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +AST_INLINE_API( +int _ast_str_make_space(struct ast_str **buf, size_t new_len, const char *file, int lineno, const char *function), +{ + _DB1(struct ast_str *old_buf = *buf;) + + if (new_len <= (*buf)->len) + return 0; /* success */ + if ((*buf)->ts == DS_ALLOCA || (*buf)->ts == DS_STATIC) + return -1; /* cannot extend */ + *buf = (struct ast_str *)__ast_realloc(*buf, new_len + sizeof(struct ast_str), file, lineno, function); + if (*buf == NULL) /* XXX watch out, we leak memory here */ + return -1; + if ((*buf)->ts != DS_MALLOC) { + pthread_setspecific((*buf)->ts->key, *buf); + _DB1(__ast_threadstorage_object_replace(old_buf, *buf, new_len + sizeof(struct ast_str));) + } + + (*buf)->len = new_len; + return 0; +} +) +#define ast_str_make_space(a,b) _ast_str_make_space(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__) +#else AST_INLINE_API( int ast_str_make_space(struct ast_str **buf, size_t new_len), { @@ -425,6 +449,7 @@ int ast_str_make_space(struct ast_str **buf, size_t new_len), return 0; } ) +#endif #define ast_str_alloca(init_len) \ ({ \ |