summaryrefslogtreecommitdiff
path: root/include/asterisk/strings.h
diff options
context:
space:
mode:
authorTilghman Lesher <tilghman@meg.abyt.es>2009-03-11 00:29:59 +0000
committerTilghman Lesher <tilghman@meg.abyt.es>2009-03-11 00:29:59 +0000
commitbfc0d3b79516774c46a9296af7a5759274611caa (patch)
treed9ce0c66f8edace25beb5e6d7b7032155aa9d5fc /include/asterisk/strings.h
parentac7e490b94accb745f8e03decfaaa449f62ebb75 (diff)
Add MALLOC_DEBUG to various utility APIs, so that memory leaks can be tracked back to their source.
(related to issue #14636) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@181028 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include/asterisk/strings.h')
-rw-r--r--include/asterisk/strings.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h
index 65664d930..94ca668a4 100644
--- a/include/asterisk/strings.h
+++ b/include/asterisk/strings.h
@@ -372,6 +372,26 @@ struct ast_str {
* \note The result of this function is dynamically allocated memory, and must
* be free()'d after it is no longer needed.
*/
+#if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
+#define ast_str_create(a) _ast_str_create(a,__FILE__,__LINE__,__PRETTY_FUNCTION__)
+AST_INLINE_API(
+struct ast_str * attribute_malloc _ast_str_create(size_t init_len,
+ const char *file, int lineno, const char *func),
+{
+ struct ast_str *buf;
+
+ buf = (struct ast_str *)__ast_calloc(1, sizeof(*buf) + init_len, file, lineno, func);
+ if (buf == NULL)
+ return NULL;
+
+ buf->__AST_STR_LEN = init_len;
+ buf->__AST_STR_USED = 0;
+ buf->__AST_STR_TS = DS_MALLOC;
+
+ return buf;
+}
+)
+#else
AST_INLINE_API(
struct ast_str * attribute_malloc ast_str_create(size_t init_len),
{
@@ -388,6 +408,7 @@ struct ast_str * attribute_malloc ast_str_create(size_t init_len),
return buf;
}
)
+#endif
/*! \brief Reset the content of a dynamic string.
* Useful before a series of ast_str_append.
@@ -665,8 +686,14 @@ enum {
* through calling one of the other functions or macros defined in this
* file.
*/
+#if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
+int __attribute__((format(printf, 4, 0))) __ast_debug_str_helper(struct ast_str **buf, size_t max_len,
+ int append, const char *fmt, va_list ap, const char *file, int lineno, const char *func);
+#define __ast_str_helper(a,b,c,d,e) __ast_debug_str_helper(a,b,c,d,e,__FILE__,__LINE__,__PRETTY_FUNCTION__)
+#else
int __attribute__((format(printf, 4, 0))) __ast_str_helper(struct ast_str **buf, size_t max_len,
int append, const char *fmt, va_list ap);
+#endif
char *__ast_str_helper2(struct ast_str **buf, size_t max_len,
const char *src, size_t maxsrc, int append, int escapecommas);