[asterisk-commits] branch russell/ast_malloc - r7455 /team/russell/ast_malloc/include/asterisk/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Dec 12 23:57:24 CST 2005


Author: russell
Date: Mon Dec 12 23:57:23 2005
New Revision: 7455

URL: http://svn.digium.com/view/asterisk?rev=7455&view=rev
Log:
merge my patch from #4996 ...

Modified:
    team/russell/ast_malloc/include/asterisk/utils.h

Modified: team/russell/ast_malloc/include/asterisk/utils.h
URL: http://svn.digium.com/view/asterisk/team/russell/ast_malloc/include/asterisk/utils.h?rev=7455&r1=7454&r2=7455&view=diff
==============================================================================
--- team/russell/ast_malloc/include/asterisk/utils.h (original)
+++ team/russell/ast_malloc/include/asterisk/utils.h Mon Dec 12 23:57:23 2005
@@ -25,6 +25,7 @@
 
 #include "asterisk/compat.h"
 
+#include <stdlib.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>	/* we want to override inet_ntoa */
 #include <netdb.h>
@@ -33,6 +34,7 @@
 #include "asterisk/lock.h"
 #include "asterisk/time.h"
 #include "asterisk/strings.h"
+#include "asterisk/logger.h"
 
 /*! \note
  \verbatim
@@ -235,4 +237,103 @@
 int getloadavg(double *list, int nelem);
 #endif
 
+#define ast_malloc(len) \
+	({ \
+		(_ast_malloc((len), __FILE__, __LINE__, __PRETTY_FUNCTION__)); \
+	})
+
+AST_INLINE_API(
+void *_ast_malloc(size_t len, const char *file, int lineno, const char *func),
+{
+	void *p;
+
+	p = malloc(len);
+
+	if (!p)
+		ast_log(LOG_ERROR, "Memory Allocation Failure - '%d' bytes in function %s at line %d of %s\n", (int)len, func, lineno, file);
+
+	return p;
+}
+)
+
+#define ast_calloc(num, len) \
+	({ \
+		(_ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)); \
+	})
+
+AST_INLINE_API(
+void *_ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func),
+{
+	void *p;
+
+	p = calloc(num, len);
+
+	if (!p)
+		ast_log(LOG_ERROR, "Memory Allocation Failure - '%d' bytes in function %s at line %d of %s\n", (int)len, func, lineno, file);
+
+	return p;
+}
+)
+
+#define ast_realloc(p, len) \
+	({ \
+		(_ast_realloc((p), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)); \
+	})
+
+AST_INLINE_API(
+void *_ast_realloc(void *p, size_t len, const char *file, int lineno, const char *func),
+{
+	void *newp;
+
+	newp = realloc(p, len);
+
+	if (!newp)
+		ast_log(LOG_ERROR, "Memory Allocation Failure - '%d' bytes in function %s at line %d of %s\n", (int)len, func, lineno, file);
+
+	return newp;
+}
+)
+
+#define ast_strdup(str) \
+	({ \
+		(_ast_strdup((str), __FILE__, __LINE__, __PRETTY_FUNCTION__)); \
+	})
+
+AST_INLINE_API(
+void *_ast_strdup(const char *str, const char *file, int lineno, const char *func),
+{
+	char *newstr = NULL;
+
+	if (str) {
+		newstr = strdup(str);
+
+		if (!newstr)
+			ast_log(LOG_ERROR, "Memory Allocation Failure - Could not duplicate '%s' in function %s at line %d of %s\n", str, func, lineno, file);
+	}
+
+	return newstr;
+}
+)
+
+#define ast_strndup(str, len) \
+	({ \
+		(_ast_strndup((str), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)); \
+	})
+
+AST_INLINE_API(
+void *_ast_strndup(const char *str, size_t len, const char *file, int lineno, const char *func),
+{
+	char *newstr = NULL;
+
+	if (str) {
+		newstr = strndup(str, len);
+
+		if (!newstr)
+			ast_log(LOG_ERROR, "Memory Allocation Failure - Could not duplicate '%d' bytes of '%s' in function %s at line %d of %s\n", (int)len, str, func, lineno, file);
+	}
+
+	return newstr;
+}
+)
+
 #endif /* _ASTERISK_UTILS_H */



More information about the asterisk-commits mailing list