From 2eb7eecdd07406e219cb1692cced6f849a2eed6a Mon Sep 17 00:00:00 2001
From: Russell Bryant <russell@russellbryant.com>
Date: Wed, 11 Jan 2006 22:41:34 +0000
Subject: [PATCH] conversions to memory allocation wrappers (issue #6210)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7991 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 apps/app_alarmreceiver.c | 13 ++++---------
 apps/app_curl.c          |  5 +++--
 apps/app_dial.c          |  7 ++-----
 apps/app_directory.c     |  2 +-
 apps/app_externalivr.c   | 13 +++++--------
 5 files changed, 15 insertions(+), 25 deletions(-)

diff --git a/apps/app_alarmreceiver.c b/apps/app_alarmreceiver.c
index 7c36b60b8c..e7310ef231 100644
--- a/apps/app_alarmreceiver.c
+++ b/apps/app_alarmreceiver.c
@@ -56,6 +56,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/localtime.h"
 #include "asterisk/callerid.h"
 #include "asterisk/astdb.h"
+#include "asterisk/utils.h"
 
 #define ALMRCV_CONFIG "alarmreceiver.conf"
 #define ADEMCO_CONTACT_ID "ADEMCO_CONTACT_ID"
@@ -579,17 +580,11 @@ static int receive_ademco_contact_id( struct ast_channel *chan, void *data, int
 
 		events_received++;
 		
-		/* Queue the Event */
-
-		if((enew = malloc(sizeof(event_node_t))) == NULL){
-			if(option_verbose >= 1)
-				ast_verbose(VERBOSE_PREFIX_1 "AlarmReceiver: Failed to allocate memory\n");
-			ast_log(LOG_WARNING, "AlarmReceiver Failed to allocate memory\n");
+		/* Queue the Event */		
+		if (!(enew = ast_calloc(1, sizeof(*enew)))) {
 			res = -1;
-                        break;
+			break;
 		}
-
-		memset(enew, 0, sizeof(event_node_t));
 		
 		enew->next = NULL;
 		ast_copy_string(enew->data, event, sizeof(enew->data));
diff --git a/apps/app_curl.c b/apps/app_curl.c
index ca715cbfa6..93d77d5717 100644
--- a/apps/app_curl.c
+++ b/apps/app_curl.c
@@ -46,6 +46,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/options.h"
 #include "asterisk/module.h"
 #include "asterisk/app.h"
+#include "asterisk/utils.h"
 
 static char *tdesc = "Load external URL";
 
@@ -63,9 +64,9 @@ static void *myrealloc(void *ptr, size_t size)
 	/* There might be a realloc() out there that doesn't like reallocing
 	   NULL pointers, so we take care of it here */
 	if (ptr)
-		return realloc(ptr, size);
+		return ast_realloc(ptr, size);
 	else
-		return malloc(size);
+		return ast_malloc(size);
 }
 
 static size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
diff --git a/apps/app_dial.c b/apps/app_dial.c
index dac6ac4ca7..e6571c9ef6 100644
--- a/apps/app_dial.c
+++ b/apps/app_dial.c
@@ -984,13 +984,10 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
 			goto out;
 		}
 		*number = '\0';
-		number++;
-		tmp = malloc(sizeof(struct localuser));
-		if (!tmp) {
-			ast_log(LOG_WARNING, "Out of memory\n");
+		number++;		
+		if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
 			goto out;
 		}
-		memset(tmp, 0, sizeof(struct localuser));
 		if (opts.flags) {
 			ast_copy_flags(tmp, &opts,
 				       OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
diff --git a/apps/app_directory.c b/apps/app_directory.c
index dd956a0185..d506df1f12 100644
--- a/apps/app_directory.c
+++ b/apps/app_directory.c
@@ -84,7 +84,7 @@ static char *convert(char *lastname)
 {
 	char *tmp;
 	int lcount = 0;
-	tmp = malloc(NUMDIGITS + 1);
+	tmp = ast_malloc(NUMDIGITS + 1);
 	if (tmp) {
 		while((*lastname > 32) && lcount < NUMDIGITS) {
 			switch(toupper(*lastname)) {
diff --git a/apps/app_externalivr.c b/apps/app_externalivr.c
index 2cf0858a2c..10232044d7 100644
--- a/apps/app_externalivr.c
+++ b/apps/app_externalivr.c
@@ -49,6 +49,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/module.h"
 #include "asterisk/linkedlists.h"
 #include "asterisk/app.h"
+#include "asterisk/utils.h"
 
 static const char *tdesc = "External IVR Interface Application";
 
@@ -112,10 +113,8 @@ static void *gen_alloc(struct ast_channel *chan, void *params)
 {
 	struct localuser *u = params;
 	struct gen_state *state;
-
-	state = calloc(1, sizeof(*state));
-
-	if (!state)
+	
+	if (!(state = ast_calloc(1, sizeof(*state))))
 		return NULL;
 
 	state->u = u;
@@ -234,10 +233,8 @@ static struct ast_generator gen =
 static struct playlist_entry *make_entry(const char *filename)
 {
 	struct playlist_entry *entry;
-
-	entry = calloc(1, sizeof(*entry) + strlen(filename) + 10);
-
-	if (!entry)
+	
+	if (!(entry = ast_calloc(1, sizeof(*entry) + strlen(filename) + 10)))
 		return NULL;
 
 	strcpy(entry->filename, filename);
-- 
GitLab